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
// SPDX-License-Identifier: MIT

use super::{
    LinkAddRequest,
    LinkDelPropRequest,
    LinkDelRequest,
    LinkGetRequest,
    LinkNewPropRequest,
    LinkSetRequest,
};
use crate::Handle;

pub struct LinkHandle(Handle);

impl LinkHandle {
    pub fn new(handle: Handle) -> Self {
        LinkHandle(handle)
    }

    pub fn set(&self, index: u32) -> LinkSetRequest {
        LinkSetRequest::new(self.0.clone(), index)
    }

    pub fn add(&self) -> LinkAddRequest {
        LinkAddRequest::new(self.0.clone())
    }

    pub fn property_add(&self, index: u32) -> LinkNewPropRequest {
        LinkNewPropRequest::new(self.0.clone(), index)
    }

    pub fn property_del(&self, index: u32) -> LinkDelPropRequest {
        LinkDelPropRequest::new(self.0.clone(), index)
    }

    pub fn del(&mut self, index: u32) -> LinkDelRequest {
        LinkDelRequest::new(self.0.clone(), index)
    }

    /// Retrieve the list of links (equivalent to `ip link show`)
    pub fn get(&mut self) -> LinkGetRequest {
        LinkGetRequest::new(self.0.clone())
    }
}