Initial commit

This commit is contained in:
Martin Berg Alstad
2024-06-22 17:19:55 +02:00
parent 9eb7c2883e
commit d5974dda20
22 changed files with 713 additions and 6 deletions

View File

@ -0,0 +1,27 @@
#[cfg(feature = "tokio")]
use {std::io::Error, tokio::fs::File, tokio_util::io::ReaderStream};
#[cfg(feature = "tokio")]
pub async fn load_file<Path>(file_path: Path) -> Result<ReaderStream<File>, Error>
where
Path: AsRef<std::path::Path>,
{
File::open(file_path).await.map(ReaderStream::new)
}
#[cfg(all(test, feature = "tokio"))]
mod tests {
use super::*;
#[tokio::test]
async fn test_load_file() {
let file = load_file("Cargo.toml").await;
assert!(file.is_ok());
}
#[tokio::test]
async fn test_load_file_error() {
let file = load_file("Cargo.tom").await;
assert!(file.is_err());
}
}