xerr

Crates.ioxerr
lib.rsxerr
version0.1.16
created_at2023-09-11 06:33:22.223563+00
updated_at2025-09-20 09:05:30.285919+00
descriptionlog error util
homepagehttps://github.com/i18n-site/rust/tree/main/xerr
repositoryhttps://github.com/i18n-site/rust.git
max_upload_size
id969295
size5,248
i18n.site (i18nsite)

documentation

README

xerr

use std::io::Read;

use xerr::ok_or;

pub fn size(path: &str) -> usize {
  ok_or!(
    {
      let mut s = String::new();
      std::fs::File::open(path)?.read_to_string(&mut s)?;
      s.len()
    },
    0
  )
}

#[cfg(test)]
mod tests {
  use super::*;

  #[test]
  fn test() {
    log_init::init();
    let result = size("not exist");
    assert_eq!(result, 0);
  }
}

About

This project is an open-source component of i18n.site ⋅ Internationalization Solution.

关于

本项目为 i18n.site ⋅ 国际化解决方案 的开源组件。

Commit count: 68

cargo fmt