Struct DeviceBuilder

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

A builder for configuring a TUN/TAP interface.

This builder allows you to set parameters such as device name, MTU, IPv4/IPv6 addresses, MAC address, and other platform-specific options.

Implementations§

Source§

impl DeviceBuilder

Source

pub fn new() -> Self

Creates a new DeviceBuilder instance with default settings.

Source

pub fn name<S: Into<String>>(self, dev_name: S) -> Self

Sets the device name.

Source

pub fn mtu(self, mtu: u16) -> Self

Sets the device MTU (Maximum Transmission Unit).

Source

pub fn mac_addr(self, mac_addr: [u8; 6]) -> Self

Sets the MAC address for the device (effective only in L2 mode).

Source

pub fn ipv4<IPv4: ToIpv4Address, Netmask: ToIpv4Netmask>( self, address: IPv4, mask: Netmask, destination: Option<IPv4>, ) -> Self

Configures the IPv4 address for the device.

  • address: The IPv4 address of the device.
  • mask: The subnet mask or prefix length.
  • destination: Optional destination address for point-to-point links.
Source

pub fn ipv6<IPv6: ToIpv6Address, Netmask: ToIpv6Netmask>( self, address: IPv6, mask: Netmask, ) -> Self

Configures an IPv6 address for the device.

  • address: The IPv6 address.
  • mask: The subnet mask or prefix length.
Source

pub fn ipv6_tuple<IPv6: ToIpv6Address, Netmask: ToIpv6Netmask>( self, addrs: &[(IPv6, Netmask)], ) -> Self

Configures multiple IPv6 addresses in batch.

Accepts a slice of (IPv6 address, netmask) tuples.

Source

pub fn layer(self, layer: Layer) -> Self

Sets the operating layer (L2 or L3) for the device.

Source

pub fn tx_queue_len(self, tx_queue_len: u32) -> Self

Sets the transmit queue length on Linux.

Source

pub fn offload(self, offload: bool) -> Self

Enables TUN offloads on Linux. After enabling, use recv_multiple/send_multiple for data transmission.

Source

pub fn multi_queue(self, multi_queue: bool) -> Self

Enables multi-queue support on Linux.

Source

pub fn packet_information(self, packet_information: bool) -> Self

Enables or disables packet information for the network driver on macOS, Linux.

This option is disabled by default (false).

Source

pub fn enable(self, enable: bool) -> Self

Enables or disables the device. Defaults to enabled.

Source

pub fn build_sync(self) -> Result<SyncDevice>

Builds a synchronous device instance and applies all configuration parameters.

Source

pub fn build_async(self) -> Result<AsyncDevice>

Builds an asynchronous device instance.

This method is available only when the async_io or async_tokio features are enabled.

Trait Implementations§

Source§

impl Default for DeviceBuilder

Source§

fn default() -> DeviceBuilder

Returns the “default value” for a type. 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.