rust-lib/src/io/file.rs
Martin Berg Alstad 0898a50166 Added MultipartFile extractors.
Moved cfg macro to lib where possible.

Changed some features, and made some deps optional
2024-06-30 20:17:44 +02:00

26 lines
582 B
Rust

use {std::io::Error, tokio::fs::File, tokio_util::io::ReaderStream};
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(test)]
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());
}
}