Struct BorrowedSocket

#[repr(transparent)]
pub struct BorrowedSocket<'socket> { pub(in ::os::windows::io::socket) socket: NotAllOnes<RawSocket>, pub(in ::os::windows::io::socket) _phantom: PhantomData<&'socket OwnedSocket> }

A borrowed socket.

This has a lifetime parameter to tie it to the lifetime of something that owns the socket.

This uses repr(transparent) and has the representation of a host socket, so it can be used in FFI in places where a socket is passed as an argument, it is not captured or consumed, and it never has the value INVALID_SOCKET.

This type's .to_owned() implementation returns another BorrowedSocket rather than an OwnedSocket. It just makes a trivial copy of the raw socket, which is then borrowed under the same lifetime.

Fields

socket: NotAllOnes<RawSocket>
_phantom: PhantomData<&'socket OwnedSocket>

Implementations

impl BorrowedSocket<'_>

const unsafe fn borrow_raw(socket: RawSocket) -> Self

Returns a BorrowedSocket holding the given raw socket.

Safety

The resource pointed to by socket must remain open for the duration of the returned BorrowedSocket, and it must not have the value INVALID_SOCKET.

impl BorrowedSocket<'_>

fn try_clone_to_owned(&self) -> Result<OwnedSocket>

Creates a new OwnedSocket instance that shares the same underlying object as the existing BorrowedSocket instance.

Trait Implementations

impl AsRawSocket for BorrowedSocket<'_>

fn as_raw_socket(&self) -> RawSocket

impl AsSocket for BorrowedSocket<'_>

fn as_socket(&self) -> BorrowedSocket<'_>

impl Debug for BorrowedSocket<'_>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<'socket> Clone for BorrowedSocket<'socket>

fn clone(&self) -> BorrowedSocket<'socket>

impl<'socket> Copy for BorrowedSocket<'socket>

impl<'socket> TrivialClone for BorrowedSocket<'socket>

Auto Trait Implementations

impl<'socket> Freeze for BorrowedSocket<'socket>

impl<'socket> RefUnwindSafe for BorrowedSocket<'socket>

impl<'socket> Send for BorrowedSocket<'socket>

impl<'socket> Sync for BorrowedSocket<'socket>

impl<'socket> Unpin for BorrowedSocket<'socket>

impl<'socket> UnsafeUnpin for BorrowedSocket<'socket>

impl<'socket> UnwindSafe for BorrowedSocket<'socket>

Blanket Implementations

impl<T> Any for BorrowedSocket<'socket> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for BorrowedSocket<'socket> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for BorrowedSocket<'socket> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for BorrowedSocket<'socket> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for BorrowedSocket<'socket>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Printable for BorrowedSocket<'socket> where T: Copy + Debug,

impl<T> SizeHint for BorrowedSocket<'socket> where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for BorrowedSocket<'socket>

impl<T> ToOwned for BorrowedSocket<'socket> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for BorrowedSocket<'socket> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for BorrowedSocket<'socket> where U: Into<T>,

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for BorrowedSocket<'socket> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>