io_lifetimes

Trait AsSocketlike

Source
pub trait AsSocketlike: AsFd {
    // Required methods
    fn as_socketlike(&self) -> BorrowedSocketlike<'_>;
    fn as_socketlike_view<Target: SocketlikeViewType>(
        &self,
    ) -> SocketlikeView<'_, Target>;
}
Expand description

A portable trait to borrow a reference from an underlying socketlike object.

This is a portability abstraction over Unix-like AsFd and Windows’ AsSocket. It also provides the as_socketlike_view convenience function providing typed views.

Required Methods§

Source

fn as_socketlike(&self) -> BorrowedSocketlike<'_>

Borrows the reference.

Source

fn as_socketlike_view<Target: SocketlikeViewType>( &self, ) -> SocketlikeView<'_, Target>

Return a borrowing view of a resource which dereferences to a &Target.

Note that Read or Write require &mut Target, but in some cases, such as TcpStream, Read and Write are implemented for &Target in addition to Target, and you can get a &mut &Target by doing &* on the resuting view, like this:

let v = s.as_socketlike_view::<std::net::TcpStream>();
(&*v).read(&mut buf).unwrap();

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: AsFd> AsSocketlike for T