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
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: impl Into<String>) -> Self
pub fn with_method(self, method: impl Into<String>) -> Self
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
- AMapping
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);
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 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.
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 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.
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