Crates.io | ok_or |
lib.rs | ok_or |
version | 0.1.2 |
source | src |
created_at | 2024-01-07 16:07:38.385619 |
updated_at | 2024-06-13 10:37:02.223828 |
description | ok_or |
homepage | https://github.com/i18n-site/rust/tree/main/ok_or |
repository | https://github.com/i18n-site/rust.git |
max_upload_size | |
id | 1091834 |
size | 2,338 |
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);
}
}