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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// src/lib.rs
//! # 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** network interface configurations programmatically.
//! - **Add or remove** network interfaces.
//! - **Save** changes back to the file system.
//! - **Fluent API** using the builder pattern for creating and modifying interfaces.
//!
//! ## Example
//!
//! ### Loading Interfaces and Modifying an Existing Interface
//!
//! ```rust
//! use interface_rs::NetworkInterfaces;
//! use interface_rs::interface::{Interface, Family, Method};
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Load interfaces (replace with an existing file path during tests)
//! let mut net_ifaces = NetworkInterfaces::load("tests/interfaces")?;
//!
//! // Retrieve and modify an existing interface
//! if let Some(iface) = net_ifaces.get_interface("eth0") {
//! let modified_iface = iface.edit()
//! .with_method(Method::Static)
//! .remove_option("address")
//! .with_option("address", "192.168.1.50")
//! .with_option("netmask", "255.255.255.0")
//! .build();
//! net_ifaces.add_interface(modified_iface);
//! }
//!
//! // Save changes
//! net_ifaces.save()?;
//! Ok(())
//! }
//! ```
//!
//! ### Adding a New Interface
//!
//! ```rust
//! use interface_rs::NetworkInterfaces;
//! use interface_rs::interface::{Interface, Family, Method};
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Load interfaces (replace with an existing file path during tests)
//! let mut net_ifaces = NetworkInterfaces::load("tests/interfaces")?;
//!
//! // Create a new interface using the builder pattern
//! net_ifaces.add_interface(
//! Interface::builder("swp1")
//! .with_auto(true)
//! .with_allow("hotplug")
//! .with_family(Family::Inet)
//! .with_method(Method::Static)
//! .with_option("address", "192.168.100.1")
//! .with_option("netmask", "255.255.255.0")
//! .build()
//! );
//!
//! // Save changes back to the file
//! net_ifaces.save()?;
//!
//! Ok(())
//! }
//! ```
//!
//! ### Deleting an Interface
//!
//! ```rust
//! use interface_rs::NetworkInterfaces;
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Load interfaces (replace with an existing file path during tests)
//! let mut net_ifaces = NetworkInterfaces::load("tests/interfaces")?;
//!
//! // Delete an interface by name
//! net_ifaces.delete_interface("eth0");
//!
//! // Save changes back to the file
//! net_ifaces.save()?;
//!
//! Ok(())
//! }
//! ```
//!
//! ## License
//!
//! This project is licensed under the MIT License.
pub use NetworkInterfacesError;
pub use ;
pub use NetworkInterfaces;