use std::io::{self, ErrorKind};
use handle_this::{Handled, Result};
pub fn io_ok() -> Result<i32> {
Ok(42)
}
pub fn io_not_found() -> Result<i32> {
Err(Handled::from(io::Error::new(ErrorKind::NotFound, "not found")))
}
pub fn chained_io_error() -> Handled {
let inner = Handled::from(io::Error::new(ErrorKind::NotFound, "inner not found"));
let outer = Handled::msg("outer error");
outer.chain_after(inner)
}
pub fn multi_io_chain() -> Handled {
let inner = Handled::from(io::Error::new(ErrorKind::NotFound, "inner not found"));
let outer = Handled::from(io::Error::new(ErrorKind::PermissionDenied, "permission denied"));
outer.chain_after(inner)
}
pub fn iter_all_fail() -> impl Iterator<Item = Result<i32>> {
vec![
Err(Handled::from(io::Error::new(ErrorKind::Other, "fail 1"))),
Err(Handled::from(io::Error::new(ErrorKind::Other, "fail 2"))),
Err(Handled::from(io::Error::new(ErrorKind::Other, "fail 3"))),
].into_iter()
}
pub fn iter_all_ok() -> impl Iterator<Item = Result<i32>> {
vec![Ok(1), Ok(2), Ok(3)].into_iter()
}
pub fn iter_second_ok() -> impl Iterator<Item = Result<i32>> {
vec![
Err(Handled::from(io::Error::new(ErrorKind::Other, "fail"))),
Ok(42),
].into_iter()
}
pub async fn async_io_ok() -> Result<i32> {
Ok(42)
}
pub async fn async_io_not_found() -> Result<i32> {
Err(Handled::from(io::Error::new(ErrorKind::NotFound, "not found")))
}
pub fn ok_val<T>(v: T) -> Result<T> {
Ok(v)
}