Struct AsyncStdTun

Source
pub struct AsyncStdTun { /* private fields */ }
Expand description

An asynchronous virtual TUN device based on the async-std/smol ecosystems.

Implementations§

Source§

impl AsyncStdTun

Source

pub fn new(name: &str, num_queues: usize) -> Result<Self>

Create a new multi-queue async Tun device, supporting the async-std/smol ecosystems, using the specified name and number of queues. The name parameter can be augmented with %d to denote a OS determined incrementing ID to assign this device. To get the real device name call TokioTun::name().

Source

pub fn name(&self) -> &str

Return the OS determined name of this device.

Source

pub fn get<I>(&self, index: I) -> Option<&AsyncStdQueue>
where I: SliceIndex<[AsyncStdQueue], Output = AsyncStdQueue>,

Retrieve an immutable reference to the specified AsyncStdQueue if the suplied SliceIndex is inbounds.

Source

pub fn get_mut<I>(&mut self, index: I) -> Option<&mut AsyncStdQueue>
where I: SliceIndex<[AsyncStdQueue], Output = AsyncStdQueue>,

Retrieve a mutable reference to the specified AsyncStdQueue if the suplied SliceIndex is inbounds.

Source

pub fn close(&mut self) -> Result<()>

Close the device destroying all internal queues. NOTE: If drain is called its on the caller to cleanup the queues.

Source

pub fn drain<R>(&mut self, range: R) -> Drain<'_, AsyncStdQueue>
where R: RangeBounds<usize>,

Drain the internal queues, passing ownership of the queue and its lifecycle to the caller. This is useful in certain scenarios where extreme control over threading and I/O operations is desired.

Source

pub fn iter(&self) -> Iter<'_, AsyncStdQueue>

Iterate over immutable instances internal AsyncStdQueue instances.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, AsyncStdQueue>

Iterate over mutable instances of the internal AsyncStdQueue instances.

Source

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

Send a packet asynchronously to an available queue. This method handles collecting all of the AsyncStdQueue::writable() futures. Then leverages select_all to await the first available queue to send the datagram via.

Source

pub async fn send_via(&self, queue: usize, datagram: &[u8]) -> Result<usize>

Send a packet asynchronously via the specified TUN queue, see the AsyncStdQueue::send() documentation for more details.

§Errors

General I/O errors are possible, along with a Error::InvalidQueue if the specified queue is out of range for this device.

Source

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

Receive a packet asynchronously from an available queue. This method handles collecting all of the AsyncStdQueue::readable() futures. Then leverages select_all to await the first available queue to send the datagram via.

Source

pub async fn recv_via(&self, queue: usize, datagram: &mut [u8]) -> Result<usize>

Receive a packet asynchronously from the specified TUN queue, see the AsyncStdQueue::recv() documentation for more details.

§Errors

General I/O errors are possible, along with a Error::InvalidQueue if the specified queue is out of range for this device.

Trait Implementations§

Source§

impl Index<usize> for AsyncStdTun

Source§

type Output = AsyncStdQueue

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &AsyncStdQueue

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for AsyncStdTun

Source§

fn index_mut(&mut self, index: usize) -> &mut AsyncStdQueue

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IntoIterator for AsyncStdTun

Source§

type Item = AsyncStdQueue

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<AsyncStdQueue>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.