Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Improving `Interface` data structure by using generic data type

Đang mở
#2,727 5 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 4 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
30/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
rust
Lĩnh vực
networking

Hướng nghiên cứu

The issue provides a Rust demo of a generic Interface<T> with BaseInterface and interface-specific data, but names no repository files or tests. First inspect the existing interface data structures and their callers to understand the scope and compatibility requirements. Done means the project’s interface representation uses the generic structure consistently and relevant tests pass; the issue has had no comment for 245 days, so check whether the direction is still wanted.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Demo code:

// SPDX-License-Identifier: Apache-2.0

#[derive(Debug, Default)]
enum InterfaceType {
    #[default]
    Unknown,
    Bond,
    LinuxBridge,
}

#[derive(Debug, Default)]
struct BaseInterface {
    name: String,
    iface_type: InterfaceType,
}

#[derive(Debug)]
struct BondInterface {
    mode: u8,
}

#[derive(Debug)]
struct LinuxBridgeInterface {
    stp: bool,
}

#[derive(Debug)]
struct Interface<T> {
    base: BaseInterface,
    specific: T,
}

impl<T> Interface<T> {
    fn new_without_type(base: BaseInterface, specific: T) -> Self {
        Self { base, specific }
    }

    fn name(&self) -> &str {
        self.base.name.as_str()
    }
}

impl Interface<LinuxBridgeInterface> {
    fn new(base: BaseInterface, bridge: LinuxBridgeInterface) -> Self {
        let mut rt = Self::new_without_type(base, bridge);
        rt.base.iface_type = InterfaceType::LinuxBridge;
        rt
    }

    fn stp(&self) -> bool {
        self.specific.stp
    }
}

impl Interface<BondInterface> {
    fn new(base: BaseInterface, bond: BondInterface) -> Self {
        let mut rt = Self::new_without_type(base, bond);
        rt.base.iface_type = InterfaceType::Bond;
        rt
    }

    fn mode(&self) -> u8 {
        self.specific.mode
    }
}

fn main() {
    let mut bond = Interface::<BondInterface>::new(
        BaseInterface {
            name: "bond0".into(),
            ..Default::default()
        },
        BondInterface { mode: 0 },
    );
    bond.specific.mode = 1;
    println!("Bond {} mode {}", bond.name(), bond.mode());

    let mut bridge = Interface::<LinuxBridgeInterface>::new(
        BaseInterface {
            name: "bond0".into(),
            ..Default::default()
        },
        LinuxBridgeInterface { stp: false },
    );
    bridge.specific.stp = true;
    println!("Bridge {} stp {}", bridge.name(), bridge.stp());
}
Ngôn ngữ chính
Rust
Star
396
Fork
121
Merge trung bình
3 ngày 11 giờ
Pull request đã merge (30 ngày)
11

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của nmstate/nmstate

Tất cả issue của nmstate/nmstate

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.