
Moved cfg macro to lib where possible. Changed some features, and made some deps optional
26 lines
582 B
Rust
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());
|
|
}
|
|
}
|