Struct InterfaceBuilder

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

A builder for constructing Interface instances.

The InterfaceBuilder struct provides a fluent API for building Interface objects. It allows you to chain method calls to set various fields, culminating in a build() method that constructs the Interface.

§Examples

use interface_rs::interface::{Interface, Family};

let iface = Interface::builder("eth0")
    .with_auto(true)
    .with_allow("hotplug")
    .with_family(Family::Inet)
    .with_method("dhcp")
    .with_option("mtu", "1500")
    .build();

Implementations§

Source§

impl InterfaceBuilder

Source

pub fn new(name: impl Into<String>) -> Self

Creates a new InterfaceBuilder with the specified interface name.

§Arguments
  • name - The name of the interface (e.g., "eth0").
§Examples
use interface_rs::interface::Interface;

let builder = Interface::builder("eth0");
Source

pub fn with_auto(self, auto: bool) -> Self

Sets whether the interface should start automatically.

§Arguments
  • auto - A boolean indicating if the interface should start automatically.
§Examples
let builder = builder.with_auto(true);
Source

pub fn with_allow(self, allow: impl Into<String>) -> Self

Adds an allow-* directive to the interface.

§Arguments
  • allow - A string representing the allow directive (e.g., "hotplug").
§Examples
let builder = builder.with_allow("hotplug");
Source

pub fn with_family(self, family: Family) -> Self

Sets the address family of the interface.

§Arguments
  • family - The Family of the interface (e.g., Family::Inet).
§Examples
use interface_rs::interface::{Interface, Family};
let builder = Interface::builder("eth0")
    .with_family(Family::Inet);
Source

pub fn with_method(self, method: impl Into<String>) -> Self

Sets the method of configuration for the interface.

§Arguments
  • method - A string representing the method (e.g., "static", "dhcp").
§Examples
let builder = Interface::builder("eth0")
    .with_method("dhcp");
Source

pub fn with_option( self, key: impl Into<String>, value: impl Into<String>, ) -> Self

Adds an option to the interface.

§Arguments
  • key - The option name (e.g., "address").
  • value - The option value (e.g., "192.168.1.100").
§Examples
let builder = Interface::builder("eth0")
    .with_option("address", "192.168.1.100");
Source

pub fn with_mapping(self, mapping: Mapping) -> Self

Sets the mapping configuration for the interface.

§Arguments
  • mapping - A Mapping struct representing the mapping configuration.
§Examples
use interface_rs::interface::{Interface, Mapping};
let mapping = Mapping {
    script: "/usr/local/bin/map-script".to_string(),
    maps: vec!["eth0".to_string()],
};
let builder = Interface::builder("eth0")
    .with_mapping(mapping);
Source

pub fn remove_option(self, key: &str) -> Self

Removes all options with the specified key from the interface configuration.

This method removes all key-value pairs in the options where the key matches the specified key.

§Arguments
  • key - The name of the option to remove (e.g., "address").
§Returns

Returns the builder instance with the specified options removed, allowing further chained method calls.

§Examples
let builder = Interface::builder("eth0")
    .with_option("address", "192.168.1.100")
    .with_option("address", "192.168.1.101")
    .remove_option("address");

// The builder no longer contains any "address" options.
Source

pub fn remove_option_value(self, key: &str, value: &str) -> Self

Removes a specific option by its key and value from the interface configuration.

This method removes only the key-value pair in the options where both the key matches the specified key and the value matches the specified value.

§Arguments
  • key - The name of the option to remove (e.g., "address").
  • value - The specific value of the option to remove (e.g., "192.168.1.100").
§Returns

Returns the builder instance with the specified key-value pair removed, allowing further chained method calls.

§Examples
let builder = Interface::builder("eth0")
    .with_option("address", "192.168.1.100")
    .with_option("address", "192.168.1.101")
    .remove_option_value("address", "192.168.1.100");

// The builder retains the option with the value "192.168.1.101" for "address",
// but the pair ("address", "192.168.1.100") is removed.
Source

pub fn build(self) -> Interface

Builds the Interface instance.

§Returns

An Interface with the specified configuration.

§Examples
use interface_rs::interface::{Interface, Family};
let iface = Interface::builder("eth0")
    .with_auto(true)
    .with_family(Family::Inet)
    .with_method("dhcp")
    .build();

Trait Implementations§

Source§

impl Clone for InterfaceBuilder

Source§

fn clone(&self) -> InterfaceBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for InterfaceBuilder

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.