Struct UdpSocket

pub struct UdpSocket { /* private fields */ }
Expand description

A UDP socket.

UDP is “connectionless”, unlike TCP. Meaning, regardless of what address you’ve bound to, a UdpSocket is free to communicate with many different remotes. In tokio there are basically two main ways to use UdpSocket:

  • one to many: bind and use send_to and recv_from to communicate with many different addresses
  • one to one: connect and associate with a single address, using send and recv to communicate only with that remote address

This type does not provide a split method, because this functionality can be achieved by instead wrapping the socket in an Arc. Note that you do not need a Mutex to share the UdpSocket — an Arc<UdpSocket> is enough. This is because all of the methods take &self instead of &mut self. Once you have wrapped it in an Arc, you can call .clone() on the Arc<UdpSocket> to get multiple shared handles to the same socket. An example of such usage can be found further down.

§Streams

TODO: document

Implementations§

§

impl UdpSocket

pub async fn bind<A>(addr: A) -> Result<UdpSocket, Box<dyn Error + Sync + Send>>

Creates a new UdpSocket, which will be bound to the specified address.

The returned socket is ready for accepting connections and connecting to others.

Binding with a port number of 0 will request that the OS assigns a port to this listener. The port allocated can be queried via the local_addr method.

pub fn from_std(socket: UdpSocket) -> Result<UdpSocket, Error>

Creates new UdpSocket from a previously bound std::net::UdpSocket.

This function is intended to be used to wrap a UDP socket from the standard library in the Tokio equivalent.

This can be used in conjunction with rama_net::socket::Socket interface to configure a socket before it’s handed off, such as setting options like reuse_address or binding to multiple addresses.

§Panics

This function panics if thread-local runtime is not set.

The runtime is usually set implicitly when this function is called from a future driven by a tokio runtime, otherwise runtime can be set explicitly with Runtime::enter function.

§Example
use rama_udp::UdpSocket;

let addr = "0.0.0.0:8080".parse::<SocketAddr>().unwrap();
let std_sock = std::net::UdpSocket::bind(addr)?;
let sock = UdpSocket::from_std(std_sock)?;
// use `sock`

pub fn into_std(self) -> Result<UdpSocket, Error>

Turns a UdpSocket into a std::net::UdpSocket.

The returned std::net::UdpSocket will have nonblocking mode set as true. Use set_nonblocking to change the blocking mode if needed.

§Examples
use rama_core::error::BoxError;
use rama_net::address::SocketAddress;

#[tokio::main]
async fn main() -> Result<(), BoxError> {
    let socket = rama_udp::UdpSocket::bind(SocketAddress::local_ipv4(0)).await?;
    let std_socket = socket.into_std()?;
    std_socket.set_nonblocking(false)?;
    Ok(())
}

pub fn as_socket(&self) -> SockRef<'_>

Expose a reference to self as a rama_net::socket::SockRef.

pub fn local_addr(&self) -> Result<SocketAddr, Error>

Returns the local address that this socket is bound to.

§Example
use rama_udp::UdpSocket;
use rama_core::error::BoxError;
use rama_net::address::SocketAddress;

let addr = SocketAddress::local_ipv4(8080);
let sock = UdpSocket::bind(addr).await?;
// the address the socket is bound to
let local_addr = sock.local_addr()?;

pub fn peer_addr(&self) -> Result<SocketAddr, Error>

Returns the socket address of the remote peer this socket was connected to.

§Example
use rama_udp::UdpSocket;
use rama_core::error::BoxError;
use rama_net::address::SocketAddress;

let addr = SocketAddress::local_ipv4(8080);
let peer = SocketAddress::local_ipv4(11100);
let sock = UdpSocket::bind(addr).await?;
sock.connect(peer).await?;
assert_eq!(peer, sock.peer_addr()?.into());

pub async fn connect<A>( &self, addr: A, ) -> Result<(), Box<dyn Error + Sync + Send>>

Connects the UDP socket setting the default destination for send() and limiting packets that are read via recv from the address specified in addr.

§Example
use rama_udp::UdpSocket;
use rama_core::error::BoxError;
use rama_net::address::SocketAddress;

let sock = UdpSocket::bind(SocketAddress::default_ipv4(8080)).await?;

let remote_addr = SocketAddress::local_ipv4(59600);
sock.connect(remote_addr).await?;
let mut buf = [0u8; 32];
// recv from remote_addr
let len = sock.recv(&mut buf).await?;
// send to remote_addr
let _len = sock.send(&buf[..len]).await?;

pub async fn send(&self, buf: &[u8]) -> Result<usize, Error>

Sends data on the socket to the remote address that the socket is connected to.

The connect method will connect this socket to a remote address. This method will fail if the socket is not connected.

§Return

On success, the number of bytes sent is returned, otherwise, the encountered error is returned.

§Cancel safety

This method is cancel safe. If send is used as the event in a [tokio::select!] statement and some other branch completes first, then it is guaranteed that the message was not sent.

§Examples
use rama_core::error::BoxError;
use rama_udp::UdpSocket;

#[tokio::main]
async fn main() -> Result<(), BoxError> {
    let socket = UdpSocket::bind("127.0.0.1:8080").await?;
    socket.connect("127.0.0.1:8081").await?;

    // Send a message
    socket.send(b"hello world").await?;

    Ok(())
}

pub async fn recv(&self, buf: &mut [u8]) -> Result<usize, Error>

Receives a single datagram message on the socket from the remote address to which it is connected. On success, returns the number of bytes read.

The function must be called with valid byte array buf of sufficient size to hold the message bytes. If a message is too long to fit in the supplied buffer, excess bytes may be discarded.

The connect method will connect this socket to a remote address. This method will fail if the socket is not connected.

§Cancel safety

This method is cancel safe. If recv is used as the event in a [tokio::select!] statement and some other branch completes first, it is guaranteed that no messages were received on this socket.

use rama_udp::UdpSocket;
use rama_core::error::BoxError;

#[tokio::main]
async fn main() -> Result<(), BoxError> {
    // Bind socket
    let socket = UdpSocket::bind("127.0.0.1:8080").await?;
    socket.connect("127.0.0.1:8081").await?;

    let mut buf = vec![0; 10];
    let n = socket.recv(&mut buf).await?;

    println!("received {} bytes {:?}", n, &buf[..n]);

    Ok(())
}

pub async fn recv_buf<B>(&self, buf: &mut B) -> Result<usize, Error>
where B: BufMut,

Receives a single datagram message on the socket from the remote address to which it is connected, advancing the buffer’s internal cursor, returning how many bytes were read.

This method must be called with valid byte array buf of sufficient size to hold the message bytes. If a message is too long to fit in the supplied buffer, excess bytes may be discarded.

This method can be used even if buf is uninitialized.

§Examples
use rama_udp::UdpSocket;
use rama_core::error::BoxError;

#[tokio::main]
async fn main() -> Result<(), BoxError> {
    let socket = UdpSocket::bind("127.0.0.1:8080").await?;
    socket.connect("127.0.0.1:8081").await?;

    let mut buf = Vec::with_capacity(512);
    let len = socket.recv_buf(&mut buf).await?;

    println!("received {} bytes {:?}", len, &buf[..len]);

    Ok(())
}

pub async fn recv_buf_from<B>( &self, buf: &mut B, ) -> Result<(usize, SocketAddress), Error>
where B: BufMut,

Receives a single datagram message on the socket, advancing the buffer’s internal cursor, returning how many bytes were read and the origin.

This method must be called with valid byte array buf of sufficient size to hold the message bytes. If a message is too long to fit in the supplied buffer, excess bytes may be discarded.

This method can be used even if buf is uninitialized.

§Notes

Note that the socket address cannot be implicitly trusted, because it is relatively trivial to send a UDP datagram with a spoofed origin in a packet injection attack. Because UDP is stateless and does not validate the origin of a packet, the attacker does not need to be able to intercept traffic in order to interfere. It is important to be aware of this when designing your application-level protocol.

§Examples
use rama_udp::UdpSocket;
use rama_core::error::BoxError;

#[tokio::main]
async fn main() -> Result<(), BoxError> {
    let socket = UdpSocket::bind("127.0.0.1:8080").await?;
    socket.connect("127.0.0.1:8081").await?;

    let mut buf = Vec::with_capacity(512);
    let (len, addr) = socket.recv_buf_from(&mut buf).await?;

    println!("received {:?} bytes from {:?}", len, addr);

    Ok(())
}

pub async fn send_to<A>( &self, buf: &[u8], addr: A, ) -> Result<usize, Box<dyn Error + Sync + Send>>

Sends data on the socket to the given address. On success, returns the number of bytes written.

§Cancel safety

This method is cancel safe. If send_to is used as the event in a [tokio::select!]- statement and some other branch completes first, then it is guaranteed that the message was not sent.

§Example
use rama_udp::UdpSocket;
use rama_core::error::BoxError;

#[tokio::main]
async fn main() -> Result<(), BoxError> {
    let socket = UdpSocket::bind("127.0.0.1:8080").await?;
    let len = socket.send_to(b"hello world", "127.0.0.1:8081").await?;

    println!("Sent {} bytes", len);

    Ok(())
}

pub async fn recv_from( &self, buf: &mut [u8], ) -> Result<(usize, SocketAddress), Error>

Receives a single datagram message on the socket. On success, returns the number of bytes read and the origin.

The function must be called with valid byte array buf of sufficient size to hold the message bytes. If a message is too long to fit in the supplied buffer, excess bytes may be discarded.

§Cancel safety

This method is cancel safe. If recv_from is used as the event in a [tokio::select!] statement and some other branch completes first, it is guaranteed that no messages were received on this socket.

§Example
use rama_udp::UdpSocket;
use rama_core::error::BoxError;

#[tokio::main]
async fn main() -> Result<(), BoxError> {
    let socket = UdpSocket::bind("127.0.0.1:8080").await?;

    let mut buf = vec![0u8; 32];
    let (len, addr) = socket.recv_from(&mut buf).await?;

    println!("received {:?} bytes from {:?}", len, addr);

    Ok(())
}
§Notes

Note that the socket address cannot be implicitly trusted, because it is relatively trivial to send a UDP datagram with a spoofed origin in a packet injection attack. Because UDP is stateless and does not validate the origin of a packet, the attacker does not need to be able to intercept traffic in order to interfere. It is important to be aware of this when designing your application-level protocol.

pub async fn peek(&self, buf: &mut [u8]) -> Result<usize, Error>

Receives a single datagram from the connected address without removing it from the queue. On success, returns the number of bytes read from whence the data came.

§Notes

On Windows, if the data is larger than the buffer specified, the buffer is filled with the first part of the data, and peek_from returns the error WSAEMSGSIZE(10040). The excess data is lost. Make sure to always use a sufficiently large buffer to hold the maximum UDP packet size, which can be up to 65536 bytes in size.

MacOS will return an error if you pass a zero-sized buffer.

If you’re merely interested in learning the sender of the data at the head of the queue, try peek_sender.

Note that the socket address cannot be implicitly trusted, because it is relatively trivial to send a UDP datagram with a spoofed origin in a packet injection attack. Because UDP is stateless and does not validate the origin of a packet, the attacker does not need to be able to intercept traffic in order to interfere. It is important to be aware of this when designing your application-level protocol.

§Examples
use rama_udp::UdpSocket;
use rama_core::error::BoxError;

#[tokio::main]
async fn main() -> Result<(), BoxError> {
    let socket = UdpSocket::bind("127.0.0.1:8080").await?;

    let mut buf = vec![0u8; 32];
    let len = socket.peek(&mut buf).await?;

    println!("peeked {:?} bytes", len);

    Ok(())
}

pub async fn peek_from( &self, buf: &mut [u8], ) -> Result<(usize, SocketAddress), Error>

Receives data from the socket, without removing it from the input queue. On success, returns the number of bytes read and the address from whence the data came.

§Notes

On Windows, if the data is larger than the buffer specified, the buffer is filled with the first part of the data, and peek_from returns the error WSAEMSGSIZE(10040). The excess data is lost. Make sure to always use a sufficiently large buffer to hold the maximum UDP packet size, which can be up to 65536 bytes in size.

MacOS will return an error if you pass a zero-sized buffer.

If you’re merely interested in learning the sender of the data at the head of the queue, try peek_sender.

Note that the socket address cannot be implicitly trusted, because it is relatively trivial to send a UDP datagram with a spoofed origin in a packet injection attack. Because UDP is stateless and does not validate the origin of a packet, the attacker does not need to be able to intercept traffic in order to interfere. It is important to be aware of this when designing your application-level protocol.

§Examples
use rama_udp::UdpSocket;
use rama_core::error::BoxError;

#[tokio::main]
async fn main() -> Result<(), BoxError> {
    let socket = UdpSocket::bind("127.0.0.1:8080").await?;

    let mut buf = vec![0u8; 32];
    let (len, addr) = socket.peek_from(&mut buf).await?;

    println!("peeked {:?} bytes from {:?}", len, addr);

    Ok(())
}

pub async fn peek_sender(&self) -> Result<SocketAddress, Error>

Retrieve the sender of the data at the head of the input queue, waiting if empty.

This is equivalent to calling peek_from with a zero-sized buffer, but suppresses the WSAEMSGSIZE error on Windows and the “invalid argument” error on macOS.

Note that the socket address cannot be implicitly trusted, because it is relatively trivial to send a UDP datagram with a spoofed origin in a packet injection attack. Because UDP is stateless and does not validate the origin of a packet, the attacker does not need to be able to intercept traffic in order to interfere. It is important to be aware of this when designing your application-level protocol.

pub fn broadcast(&self) -> Result<bool, Error>

Gets the value of the SO_BROADCAST option for this socket.

For more information about this option, see set_broadcast.

pub fn set_broadcast(&self, on: bool) -> Result<(), Error>

Sets the value of the SO_BROADCAST option for this socket.

When enabled, this socket is allowed to send packets to a broadcast address.

pub fn multicast_loop_v4(&self) -> Result<bool, Error>

Gets the value of the IP_MULTICAST_LOOP option for this socket.

For more information about this option, see set_multicast_loop_v4.

pub fn set_multicast_loop_v4(&self, on: bool) -> Result<(), Error>

Sets the value of the IP_MULTICAST_LOOP option for this socket.

If enabled, multicast packets will be looped back to the local socket.

§Note

This may not have any affect on IPv6 sockets.

pub fn multicast_ttl_v4(&self) -> Result<u32, Error>

Gets the value of the IP_MULTICAST_TTL option for this socket.

For more information about this option, see set_multicast_ttl_v4.

pub fn set_multicast_ttl_v4(&self, ttl: u32) -> Result<(), Error>

Sets the value of the IP_MULTICAST_TTL option for this socket.

Indicates the time-to-live value of outgoing multicast packets for this socket. The default value is 1 which means that multicast packets don’t leave the local network unless explicitly requested.

§Note

This may not have any affect on IPv6 sockets.

pub fn multicast_loop_v6(&self) -> Result<bool, Error>

Gets the value of the IPV6_MULTICAST_LOOP option for this socket.

For more information about this option, see set_multicast_loop_v6.

pub fn set_multicast_loop_v6(&self, on: bool) -> Result<(), Error>

Sets the value of the IPV6_MULTICAST_LOOP option for this socket.

Controls whether this socket sees the multicast packets it sends itself.

§Note

This may not have any affect on IPv4 sockets.

pub fn ttl(&self) -> Result<u32, Error>

Gets the value of the IP_TTL option for this socket.

For more information about this option, see set_ttl.

§Examples
use rama_udp::UdpSocket;
use rama_core::error::BoxError;

let sock = UdpSocket::bind("127.0.0.1:8080").await?;

println!("{:?}", sock.ttl()?);

pub fn set_ttl(&self, ttl: u32) -> Result<(), Error>

Sets the value for the IP_TTL option on this socket.

This value sets the time-to-live field that is used in every packet sent from this socket.

§Examples
use rama_udp::UdpSocket;
use rama_core::error::BoxError;

let sock = UdpSocket::bind("127.0.0.1:8080").await?;
sock.set_ttl(60)?;

pub fn join_multicast_v4( &self, multiaddr: Ipv4Addr, interface: Ipv4Addr, ) -> Result<(), Error>

Executes an operation of the IP_ADD_MEMBERSHIP type.

This function specifies a new multicast group for this socket to join. The address must be a valid multicast address, and interface is the address of the local interface with which the system should join the multicast group. If it’s equal to INADDR_ANY then an appropriate interface is chosen by the system.

pub fn join_multicast_v6( &self, multiaddr: Ipv6Addr, interface: u32, ) -> Result<(), Error>

Executes an operation of the IPV6_ADD_MEMBERSHIP type.

This function specifies a new multicast group for this socket to join. The address must be a valid multicast address, and interface is the index of the interface to join/leave (or 0 to indicate any interface).

pub fn leave_multicast_v4( &self, multiaddr: Ipv4Addr, interface: Ipv4Addr, ) -> Result<(), Error>

Executes an operation of the IP_DROP_MEMBERSHIP type.

For more information about this option, see join_multicast_v4.

pub fn leave_multicast_v6( &self, multiaddr: Ipv6Addr, interface: u32, ) -> Result<(), Error>

Executes an operation of the IPV6_DROP_MEMBERSHIP type.

For more information about this option, see join_multicast_v6.

pub fn take_error(&self) -> Result<Option<Error>, Error>

Returns the value of the SO_ERROR option.

§Examples
use rama_udp::UdpSocket;
use rama_core::error::BoxError;

#[tokio::main]
async fn main() -> Result<(), BoxError> {
    let socket = UdpSocket::bind("0.0.0.0:8080").await?;

    if let Ok(Some(err)) = socket.take_error() {
        println!("Got error: {:?}", err);
    }

    Ok(())
}

pub fn into_framed<C>(self, codec: C) -> UdpFramed<C>

Consume this UdpSocket into a UdpFramed using the given C codec.

Trait Implementations§

§

impl AsFd for UdpSocket

§

fn as_fd(&self) -> BorrowedFd<'_>

Borrows the file descriptor. Read more
§

impl AsRawFd for UdpSocket

§

fn as_raw_fd(&self) -> i32

Extracts the raw file descriptor. Read more
§

impl Debug for UdpSocket

§

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

Formats the value using the given formatter. Read more
§

impl From<UdpSocket> for UdpSocket

§

fn from(value: UdpSocket) -> UdpSocket

Converts to this type from the input type.
§

impl TryFrom<Socket> for UdpSocket

§

type Error = Error

The type returned in the event of a conversion error.
§

fn try_from( value: Socket, ) -> Result<UdpSocket, <UdpSocket as TryFrom<Socket>>::Error>

Performs the conversion.
§

impl TryFrom<UdpSocket> for UdpSocket

§

fn try_from( stream: UdpSocket, ) -> Result<UdpSocket, <UdpSocket as TryFrom<UdpSocket>>::Error>

Consumes stream, returning the tokio I/O object.

This is equivalent to UdpSocket::from_std(stream).

§

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

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

Mutably borrows from an owned value. Read more
§

impl<T> Conv for T

§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
§

impl<T> FmtForward for T

§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pipe for T
where T: ?Sized,

§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<S, P, B, E>(self, other: P) -> And<T, P>
where T: Policy<S, B, E>, P: Policy<S, B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
§

fn or<S, P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<S, B, E>, P: Policy<S, B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> Tap for T

§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
§

impl<T> TryConv for T

§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T