use std::fs::File;
use std::io;
use std::ops::Deref;
use std::ops::DerefMut;
use base::AsRawDescriptor;
use base::RawDescriptor;
#[cfg(any(target_os = "android", target_os = "linux"))]
use base::UnixSeqpacket;
use crate::sys::platform::AsyncErrorSys;
#[remain::sorted]
#[derive(Debug, thiserror::Error)]
pub enum AsyncError {
    #[error("An error with an EventAsync: {0}")]
    EventAsync(base::Error),
    #[error("IO error: {0}")]
    Io(std::io::Error),
    #[error("Platform-specific error: {0}")]
    SysVariants(#[from] AsyncErrorSys),
}
pub type AsyncResult<T> = std::result::Result<T, AsyncError>;
impl From<AsyncError> for io::Error {
    fn from(e: AsyncError) -> Self {
        match e {
            AsyncError::EventAsync(e) => e.into(),
            AsyncError::Io(e) => e,
            AsyncError::SysVariants(e) => e.into(),
        }
    }
}
pub trait IntoAsync: AsRawDescriptor {}
impl IntoAsync for File {}
#[cfg(any(target_os = "android", target_os = "linux"))]
impl IntoAsync for UnixSeqpacket {}
pub struct AsyncWrapper<T>(T);
impl<T> AsyncWrapper<T> {
    pub fn new(val: T) -> Self {
        AsyncWrapper(val)
    }
    pub fn into_inner(self) -> T {
        self.0
    }
}
impl<T> Deref for AsyncWrapper<T> {
    type Target = T;
    fn deref(&self) -> &T {
        &self.0
    }
}
impl<T> DerefMut for AsyncWrapper<T> {
    fn deref_mut(&mut self) -> &mut T {
        &mut self.0
    }
}
impl<T: AsRawDescriptor> AsRawDescriptor for AsyncWrapper<T> {
    fn as_raw_descriptor(&self) -> RawDescriptor {
        self.0.as_raw_descriptor()
    }
}
impl<T: AsRawDescriptor> IntoAsync for AsyncWrapper<T> {}