3 releases

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

#39 in #ok

Download history 144/week @ 2024-06-10 8/week @ 2024-06-17 15/week @ 2024-07-22 115/week @ 2024-08-12 15/week @ 2024-08-19

141 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

~130KB