interface_rs::network_interfaces

Struct NetworkInterfaces

Source
pub struct NetworkInterfaces {
    pub interfaces: HashMap<String, Interface>,
    /* private fields */
}
Expand description

Represents the collection of network interfaces defined in an interfaces(5) file.

The NetworkInterfaces struct provides methods to load, manipulate, and save network interface configurations.

§Examples

Loading and modifying interfaces:

use interface_rs::NetworkInterfaces;
use interface_rs::interface::Interface;

let mut net_ifaces = NetworkInterfaces::load("/path/to/interfaces").unwrap();

// Modify an interface
if let Some(iface) = net_ifaces.interfaces.get_mut("eth0") {
    iface.method = Some("static".to_string());
    iface.options.push(("address".to_string(), "192.168.1.100".to_string()));
}

// Save changes
net_ifaces.save().unwrap();

Fields§

§interfaces: HashMap<String, Interface>

A mapping of interface names to their configurations.

Implementations§

Source§

impl NetworkInterfaces

Source

pub fn load<P: AsRef<Path>>(path: P) -> Result<Self, NetworkInterfacesError>

Loads the interfaces(5) file into memory.

§Arguments
  • path - The path to the interfaces file.
§Returns

A NetworkInterfaces instance containing the parsed interfaces.

§Errors

Returns a NetworkInterfacesError if the file cannot be read or parsed.

Source

pub fn get_interface(&self, name: &str) -> Option<&Interface>

Retrieves a reference to an interface by name.

§Arguments
  • name - The name of the interface.
§Returns

An Option containing a reference to the Interface if found.

Source

pub fn add_interface(&mut self, iface: Interface)

Adds or updates an interface in the collection.

§Arguments
  • iface - The Interface to add or update.
Source

pub fn delete_interface(&mut self, name: &str)

Deletes an interface by name.

§Arguments
  • name - The name of the interface to delete.
Source

pub fn save(&mut self) -> Result<(), NetworkInterfacesError>

Saves changes back to the interfaces(5) file.

§Errors

Returns a NetworkInterfacesError if the file cannot be written or has been modified on disk.

Source

pub fn reload(&mut self) -> Result<(), NetworkInterfacesError>

Reloads the interfaces file from disk.

§Errors

Returns a NetworkInterfacesError if the file cannot be read or parsed.

Trait Implementations§

Source§

impl Debug for NetworkInterfaces

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for NetworkInterfaces

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> 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> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.