pub struct Interface {
pub name: String,
pub auto: bool,
pub allow: Vec<String>,
pub family: Option<Family>,
pub method: Option<String>,
pub options: Vec<(String, String)>,
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};
let iface = Interface::builder("eth0")
.with_auto(true)
.with_allow("hotplug")
.with_family(Family::Inet)
.with_method("dhcp")
.with_option("mtu", "1500")
.build();
Fields§
§name: String
The name of the interface (e.g., "eth0"
).
auto: bool
Indicates 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<String>
The method of configuration (e.g., "static"
, "dhcp"
).
options: Vec<(String, String)>
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};
let iface = Interface::builder("eth0")
.with_auto(true)
.with_family(Family::Inet)
.with_method("dhcp")
.build();
// Modify the existing interface
let modified_iface = iface.edit()
.with_method("static")
.with_option("address", "192.168.1.50")
.build();
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Interface
impl RefUnwindSafe for Interface
impl Send for Interface
impl Sync for Interface
impl Unpin for Interface
impl UnwindSafe for Interface
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)