1
use std::{io, num::TryFromIntError};
2

            
3
pub trait ToIoResult<T> {
4
    fn to_io(self) -> io::Result<T>;
5
}
6

            
7
impl<T> ToIoResult<T> for std::result::Result<T, TryFromIntError> {
8
117532
    fn to_io(self) -> io::Result<T> {
9
117532
        match self {
10
117532
            Ok(result) => Ok(result),
11
            Err(err) => Err(io::Error::new(io::ErrorKind::Other, err)),
12
        }
13
117532
    }
14
}
15

            
16
impl<T, U> ToIoResult<T> for Result<T, flume::SendError<U>> {
17
2471
    fn to_io(self) -> io::Result<T> {
18
2471
        match self {
19
2471
            Ok(value) => Ok(value),
20
            Err(_) => Err(io::Error::new(
21
                io::ErrorKind::BrokenPipe,
22
                "sender disconnected",
23
            )),
24
        }
25
2471
    }
26
}