3 releases

0.1.3 Aug 17, 2024
0.1.2 Jun 13, 2024
0.1.1 Jan 7, 2024

#37 in #ok

Download history 4/week @ 2024-07-21 11/week @ 2024-07-28 87/week @ 2024-08-11 42/week @ 2024-08-18 1/week @ 2024-08-25 15/week @ 2024-09-15 28/week @ 2024-09-22 16/week @ 2024-09-29

182 downloads per month

MulanPSL-2.0

4KB

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 ⋅ 国际化解决方案 的开源组件。

Dependencies

~135KB