pub struct Interface {
pub name: String,
pub auto: bool,
pub allow: Vec<String>,
pub family: Option<Family>,
pub method: Option<Method>,
pub options: Vec<InterfaceOption>,
pub mapping: Option<Mapping>,
}Expand description
Represents a network interface configuration in an interfaces(5) file.
The Interface struct encapsulates all the configuration details for a
network interface, including its name, whether it starts automatically,
allowed hotplug options, address family, method of configuration, and
additional options.
To construct an Interface, it is recommended to use the InterfaceBuilder
via the Interface::builder method for a more ergonomic and fluent API.
§Examples
Creating a new Interface using the builder pattern:
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();Fields§
§name: StringThe name of the interface (e.g., "eth0").
auto: boolIndicates if the interface is set to start automatically.
allow: Vec<String>A list of allow-* directives associated with the interface.
family: Option<Family>The address family (e.g., inet).
method: Option<Method>The method of configuration (e.g., static, dhcp).
options: Vec<InterfaceOption>A list of options specified under the iface stanza.
mapping: Option<Mapping>Optional mapping configuration for the interface.
Implementations§
Source§impl Interface
impl Interface
Sourcepub fn builder(name: impl Into<String>) -> InterfaceBuilder
pub fn builder(name: impl Into<String>) -> InterfaceBuilder
Creates a new InterfaceBuilder for constructing an Interface.
§Arguments
name- The name of the interface (e.g.,"eth0").
§Examples
use interface_rs::interface::Interface;
let builder = Interface::builder("eth0");Sourcepub fn edit(&self) -> InterfaceBuilder
pub fn edit(&self) -> InterfaceBuilder
Creates a new InterfaceBuilder initialized with this Interface’s data.
This method allows you to modify an existing Interface using the builder pattern.
§Examples
use interface_rs::interface::{Interface, Family, Method};
let iface = Interface::builder("eth0")
.with_auto(true)
.with_family(Family::Inet)
.with_method(Method::Dhcp)
.build();
// Modify the existing interface
let modified_iface = iface.edit()
.with_method(Method::Static)
.with_option("address", "192.168.1.50")
.build();Sourcepub fn get_option(&self, key: &str) -> Option<String>
pub fn get_option(&self, key: &str) -> Option<String>
Returns the first value for the given option key.
§Arguments
key- The option name to look up (e.g.,"address","netmask").
§Returns
Some(String) if the option exists, None otherwise.
§Examples
use interface_rs::interface::{Interface, Method};
let iface = Interface::builder("eth0")
.with_method(Method::Static)
.with_option("address", "192.168.1.100")
.with_option("netmask", "255.255.255.0")
.build();
assert_eq!(iface.get_option("address"), Some("192.168.1.100".to_string()));
assert_eq!(iface.get_option("gateway"), None);Sourcepub fn get_options(&self, key: &str) -> Vec<String>
pub fn get_options(&self, key: &str) -> Vec<String>
Returns all values for the given option key.
Some options like address can appear multiple times. This method
returns all values for a given key.
§Arguments
key- The option name to look up.
§Returns
A Vec of strings containing all values for the key.
§Examples
use interface_rs::interface::{Interface, Method};
let iface = Interface::builder("eth0")
.with_method(Method::Static)
.with_option("address", "192.168.1.100")
.with_option("address", "192.168.1.101")
.build();
let addresses = iface.get_options("address");
assert_eq!(addresses, vec!["192.168.1.100", "192.168.1.101"]);