1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Take a look at the license at the top of the repository in the LICENSE file.

#[cfg(any(feature = "v2_74", feature = "dox"))]
use crate::glib::translate::*;
#[cfg(any(feature = "v2_74", feature = "dox"))]
use crate::glib::FileError;
use crate::IOErrorEnum;
use std::io;

impl From<IOErrorEnum> for io::ErrorKind {
    fn from(kind: IOErrorEnum) -> Self {
        match kind {
            IOErrorEnum::NotFound => Self::NotFound,
            IOErrorEnum::Exists => Self::AlreadyExists,
            IOErrorEnum::InvalidFilename => Self::InvalidInput,
            IOErrorEnum::InvalidArgument => Self::InvalidInput,
            IOErrorEnum::PermissionDenied => Self::PermissionDenied,
            IOErrorEnum::AddressInUse => Self::AddrInUse,
            IOErrorEnum::TimedOut => Self::TimedOut,
            IOErrorEnum::WouldBlock => Self::WouldBlock,
            IOErrorEnum::InvalidData => Self::InvalidData,
            IOErrorEnum::ConnectionRefused => Self::ConnectionRefused,
            IOErrorEnum::BrokenPipe => Self::BrokenPipe,
            IOErrorEnum::NotConnected => Self::NotConnected,
            _ => Self::Other,
        }
    }
}

pub(crate) fn to_std_io_result<T>(result: Result<T, glib::Error>) -> io::Result<T> {
    result.map_err(|g_error| match g_error.kind::<IOErrorEnum>() {
        Some(io_error_enum) => io::Error::new(io_error_enum.into(), g_error),
        None => io::Error::new(io::ErrorKind::Other, g_error),
    })
}

#[cfg(any(feature = "v2_74", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_74")))]
impl From<FileError> for IOErrorEnum {
    #[doc(alias = "g_io_error_from_file_error")]
    fn from(e: FileError) -> Self {
        unsafe { from_glib(ffi::g_io_error_from_file_error(e.into_glib())) }
    }
}