interface_rs/lib.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
//! # interface-rs
//!
//! A Rust library for parsing and manipulating an `interfaces(5)` file.
//!
//! This library provides structs and functions to load, parse, modify, and save
//! network interface configurations in the Debian-style `interfaces(5)` file
//! format. This file is typically found at `/etc/network/interfaces` on Debian-based
//! systems but may be located elsewhere depending on your system configuration.
//!
//! ## Features
//!
//! - **Load and parse** existing configurations from an `interfaces(5)` file.
//! - **Modify** interface configurations programmatically.
//! - **Save** changes back to the file system.
//!
//! ## Example
//!
//! ```rust
//! use interface_rs::NetworkInterfaces;
//! use interface_rs::interface::{Interface, Family};
//!
//! fn main() -> std::io::Result<()> {
//! // Load the interfaces file
//! let mut net_ifaces = NetworkInterfaces::load("/path/to/interfaces")?;
//!
//! // Add a new interface
//! let new_iface = Interface {
//! name: "eth2".to_string(),
//! auto: true,
//! allow: vec!["hotplug".to_string()],
//! family: Some(Family::Inet),
//! method: Some("static".to_string()),
//! options: vec![
//! ("address".to_string(), "192.168.1.100".to_string()),
//! ("netmask".to_string(), "255.255.255.0".to_string()),
//! ],
//! mapping: None,
//! };
//! net_ifaces.add_interface(new_iface);
//!
//! // Save changes
//! net_ifaces.save()?;
//!
//! Ok(())
//! }
//! ```
//!
//! ## License
//!
//! This project is licensed under the MIT License.
pub mod interface;
pub mod network_interfaces;
mod parser;
pub mod error;
pub use network_interfaces::NetworkInterfaces;
pub use interface::{Interface, Family, Mapping};
pub use error::NetworkInterfacesError;