ok_or

Crates.iook_or
lib.rsok_or
version0.1.3
sourcesrc
created_at2024-01-07 16:07:38.385619
updated_at2024-08-17 13:10:36.255858
descriptionok_or
homepagehttps://github.com/i18n-site/rust/tree/main/ok_or
repositoryhttps://github.com/i18n-site/rust.git
max_upload_size
id1091834
size3,550
i18n.site (i18nsite)

documentation

README

ok_or

use std::io::Read;

use ok_or::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() {
    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: 21

cargo fmt