dope-core 0.76.0

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

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

mod sealed;

pub(crate) use sealed::Sealed;

use crate::io::socket::{self, StreamSpec};

/// Validated, byte-stable storage for a retained socket operation.
pub trait Prepared: Sealed + Copy {
    fn view(&self) -> View<'_>;

    fn stream_spec(&self) -> StreamSpec;
}

/// A validated address borrowed for one socket operation.
pub struct View<'a>(pub(crate) addr::Addr<'a>);

impl<'a> View<'a> {
    /// Reads the local address into the caller's storage.
    pub fn local(
        fd: fd::BorrowedFd<'_>,
        storage: &'a mut addr::Storage,
    ) -> Result<Self, addr::Local<Errno>> {
        addr::Addr::local::<crate::Backend, Errno>(fd, storage).map(Self)
    }

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

    pub(crate) fn native(self) -> addr::Addr<'a> {
        self.0
    }
}