rtnetlink/link/
dummy.rs

1// SPDX-License-Identifier: MIT
2
3use crate::{link::LinkMessageBuilder, packet_route::link::InfoKind};
4
5/// Represent dummy interface.
6/// Example code on creating a dummy interface
7/// ```no_run
8/// use rtnetlink::{new_connection, LinkDummy};
9/// #[tokio::main]
10/// async fn main() -> Result<(), String> {
11///     let (connection, handle, _) = new_connection().unwrap();
12///     tokio::spawn(connection);
13///
14///     handle
15///         .link()
16///         .add(LinkDummy::new("dummy0").build())
17///         .execute()
18///         .await
19///         .map_err(|e| format!("{e}"))
20/// }
21/// ```
22///
23/// Please check LinkMessageBuilder::<LinkDummy> for more detail.
24#[derive(Debug)]
25pub struct LinkDummy;
26
27impl LinkDummy {
28    /// Equal to `LinkMessageBuilder::<LinkDummy>::new()`
29    pub fn new(name: &str) -> LinkMessageBuilder<Self> {
30        LinkMessageBuilder::<LinkDummy>::new(name)
31    }
32}
33
34impl LinkMessageBuilder<LinkDummy> {
35    /// Create [LinkMessageBuilder] for dummy interface type
36    pub fn new(name: &str) -> Self {
37        LinkMessageBuilder::<LinkDummy>::new_with_info_kind(InfoKind::Dummy)
38            .name(name.to_string())
39    }
40}