dope-core 0.77.0

Owned native I/O and completion driver for dope
Documentation
use std::{os::unix, path};

use dope_sys::io::socket::{Domain, addr};

use crate::io::socket::{Addr, Prepared, StreamSpec, addr::prepared};

/// A compact, validated Unix-domain socket address.
#[derive(Clone, Copy)]
pub struct Unix(addr::Unix);

impl Unix {
    pub fn from_path(path: &path::Path) -> Result<Self, addr::PathError> {
        let bytes = unix::ffi::OsStrExt::as_bytes(path.as_os_str());
        addr::Unix::from_path::<crate::Backend>(bytes).map(Self)
    }
}

impl prepared::Sealed for Unix {}

impl Prepared for Unix {
    fn view(&self) -> prepared::View<'_> {
        prepared::View(self.0.as_addr())
    }

    fn stream_spec(&self) -> StreamSpec {
        StreamSpec(Domain::Unix)
    }
}

const _: () = {
    assert!(size_of::<addr::Unix>() == size_of::<Unix>());
    assert!(size_of::<Unix>() < size_of::<Addr>());
};