dope-core 0.76.0

Owned native I/O and completion driver for dope
Documentation
pub(in crate::io::socket) mod inet;
pub(in crate::io::socket) mod prepared;
pub(in crate::io::socket) mod unix;

use std::net;

use dope_sys::io::socket::addr;

use crate::{Backend, io::socket};

#[derive(Clone, Copy)]
#[repr(transparent)]
pub struct Addr(addr::Storage<addr::Socklen>);

impl Addr {
    pub fn from_std(address: net::SocketAddr) -> Self {
        let native = addr::Internet::from_std::<Backend>(&address);
        Self(addr::Storage::from_addr(native.as_addr()))
    }

    pub fn into_std(self) -> Result<net::SocketAddr, socket::Error> {
        self.0.to_std().map_err(socket::Error::from)
    }

    pub(crate) const STORAGE_CAPACITY: usize = addr::CAPACITY;

    pub(crate) fn try_parse(name: &[u8]) -> Result<net::SocketAddr, socket::Error> {
        addr::Internet::try_parse(name).map_err(socket::Error::from)
    }
}

impl From<prepared::View<'_>> for Addr {
    fn from(view: prepared::View<'_>) -> Self {
        Self(addr::Storage::from_addr(view.native()))
    }
}