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, Method};
let iface = Interface::builder("eth0")
.with_auto(true)
.with_allow("hotplug")
.with_family(Family::Inet)
.with_method(Method::Dhcp)
.with_option("mtu", "1500")
.build();Implementations§
Source§impl InterfaceBuilder
impl InterfaceBuilder
Sourcepub fn with_allow(self, allow: impl Into<String>) -> Self
pub fn with_allow(self, allow: impl Into<String>) -> Self
Sourcepub fn with_family(self, family: Family) -> Self
pub fn with_family(self, family: Family) -> Self
Sourcepub fn with_method(self, method: Method) -> Self
pub fn with_method(self, method: Method) -> Self
Sourcepub fn with_option(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_option( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Adds an option to the interface using string key-value pairs.
This method parses the key and value into the appropriate InterfaceOption
variant automatically.
§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");Sourcepub fn with_typed_option(self, option: InterfaceOption) -> Self
pub fn with_typed_option(self, option: InterfaceOption) -> Self
Adds a typed option to the interface.
§Arguments
option- TheInterfaceOptionto add.
§Examples
use interface_rs::interface::{Interface, InterfaceOption};
let builder = Interface::builder("eth0")
.with_typed_option(InterfaceOption::Mtu(1500))
.with_typed_option(InterfaceOption::Address("192.168.1.100".to_string()));Sourcepub fn with_mapping(self, mapping: Mapping) -> Self
pub fn with_mapping(self, mapping: Mapping) -> Self
Sets the mapping configuration for the interface.
§Arguments
mapping- AMappingstruct representing the mapping configuration.
§Examples
use interface_rs::interface::{Interface, Mapping};
use std::path::PathBuf;
let mapping = Mapping {
script: PathBuf::from("/usr/local/bin/map-script"),
maps: vec!["eth0".to_string()],
};
let builder = Interface::builder("eth0")
.with_mapping(mapping);Sourcepub fn remove_option(self, key: &str) -> Self
pub fn remove_option(self, key: &str) -> Self
Removes all options with the specified key from the interface configuration.
This method removes all options where the name 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.Sourcepub fn remove_option_value(self, key: &str, value: &str) -> Self
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 option where both the name 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 option 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.Trait Implementations§
Source§impl Clone for InterfaceBuilder
impl Clone for InterfaceBuilder
Source§fn clone(&self) -> InterfaceBuilder
fn clone(&self) -> InterfaceBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more