Skip to content

Commit 0b98180

Browse files
committed
Mark all public struct/enum as non_exhaustive
All the public struct/enum in nmstate might add members/type, hence marking them as non_exhaustive which will prevent API user from in-compatibility usage. This allows us to only preserve API compatibility when adding new member to struct or enum. Please refer to https://doc.rust-lang.org/reference/attributes/type_system.html for more detail. Signed-off-by: Gris Ge <[email protected]>
1 parent 28ecabc commit 0b98180

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+100
-17
lines changed

examples/new_rule.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,26 @@ fn main() {
1111
let _port_number = socket.bind_auto().unwrap().port_number();
1212
socket.connect(&SocketAddr::new(0, 0)).unwrap();
1313

14+
let mut rule_msg_hdr = RuleHeader::default();
15+
rule_msg_hdr.family = AF_INET as u8;
16+
rule_msg_hdr.table = RT_TABLE_DEFAULT;
17+
rule_msg_hdr.action = FR_ACT_TO_TBL;
18+
19+
let mut rule_msg = RuleMessage::default();
20+
rule_msg.header = rule_msg_hdr;
21+
rule_msg.nlas = vec![
22+
rule::Nla::Table(254),
23+
rule::Nla::SuppressPrefixLen(4294967295),
24+
rule::Nla::Priority(1000),
25+
rule::Nla::Protocol(2),
26+
];
27+
1428
let mut msg = NetlinkMessage {
1529
header: NetlinkHeader {
1630
flags: NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL | NLM_F_ACK,
1731
..Default::default()
1832
},
19-
payload: NetlinkPayload::from(RtnlMessage::NewRule(RuleMessage {
20-
header: RuleHeader {
21-
family: AF_INET as u8,
22-
table: RT_TABLE_DEFAULT,
23-
action: FR_ACT_TO_TBL,
24-
..Default::default()
25-
},
26-
nlas: vec![
27-
rule::Nla::Table(254),
28-
rule::Nla::SuppressPrefixLen(4294967295),
29-
rule::Nla::Priority(1000),
30-
rule::Nla::Protocol(2),
31-
],
32-
})),
33+
payload: NetlinkPayload::from(RtnlMessage::NewRule(rule_msg)),
3334
};
3435

3536
msg.finalize();

src/rtnl/address/message.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ use crate::{
99
};
1010

1111
#[derive(Debug, PartialEq, Eq, Clone, Default)]
12+
#[non_exhaustive]
1213
pub struct AddressMessage {
1314
pub header: AddressHeader,
1415
pub nlas: Vec<Nla>,
1516
}
1617

1718
#[derive(Debug, PartialEq, Eq, Clone, Default)]
19+
#[non_exhaustive]
1820
pub struct AddressHeader {
1921
pub family: u8,
2022
pub prefix_len: u8,

src/rtnl/address/nlas/cache_info.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::{
66
};
77

88
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
9+
#[non_exhaustive]
910
pub struct CacheInfo {
1011
pub ifa_preferred: i32,
1112
pub ifa_valid: i32,

src/rtnl/address/nlas/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::{
1717
};
1818

1919
#[derive(Debug, PartialEq, Eq, Clone)]
20+
#[non_exhaustive]
2021
pub enum Nla {
2122
Unspec(Vec<u8>),
2223
Address(Vec<u8>),

src/rtnl/link/header.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use crate::{
2525
///
2626
/// `LinkHeader` exposes all these fields except for the "reserved" one.
2727
#[derive(Debug, PartialEq, Eq, Clone, Default)]
28+
#[non_exhaustive]
2829
pub struct LinkHeader {
2930
/// Address family: one of the `AF_*` constants.
3031
pub interface_family: u8,

src/rtnl/link/message.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::{
99
};
1010

1111
#[derive(Debug, PartialEq, Eq, Clone, Default)]
12+
#[non_exhaustive]
1213
pub struct LinkMessage {
1314
pub header: LinkHeader,
1415
pub nlas: Vec<Nla>,

src/rtnl/link/nlas/af_spec_bridge.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::{
1515
use byteorder::{ByteOrder, NativeEndian};
1616

1717
#[derive(Clone, Eq, PartialEq, Debug)]
18+
#[non_exhaustive]
1819
pub enum AfSpecBridge {
1920
Flags(u16),
2021
VlanInfo(BridgeVlanInfo),
@@ -75,6 +76,7 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for AfSpecBridge {
7576
}
7677

7778
#[derive(Debug, PartialEq, Eq, Clone, Copy, Default)]
79+
#[non_exhaustive]
7880
pub struct BridgeVlanInfo {
7981
pub flags: u16,
8082
pub vid: u16,

src/rtnl/link/nlas/af_spec_inet.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::{
1111
};
1212

1313
#[derive(Clone, Eq, PartialEq, Debug)]
14+
#[non_exhaustive]
1415
pub enum AfSpecInet {
1516
Unspec(Vec<u8>),
1617
Unix(Vec<u8>),

src/rtnl/link/nlas/bond.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::{
1616
};
1717

1818
#[derive(Debug, Clone, Eq, PartialEq)]
19+
#[non_exhaustive]
1920
pub enum BondAdInfo {
2021
Aggregator(u16),
2122
NumPorts(u16),
@@ -152,6 +153,7 @@ impl Nla for BondIpAddrNla {
152153
}
153154

154155
#[derive(Debug, PartialEq, Eq, Clone)]
156+
#[non_exhaustive]
155157
pub enum InfoBond {
156158
Mode(u8),
157159
ActiveSlave(u32),

src/rtnl/link/nlas/bridge.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const BRIDGE_QUERIER_IPV6_PORT: u16 = 6;
2424
const BRIDGE_QUERIER_IPV6_OTHER_TIMER: u16 = 7;
2525

2626
#[derive(Debug, PartialEq, Eq, Clone)]
27+
#[non_exhaustive]
2728
pub enum InfoBridge {
2829
Unspec(Vec<u8>),
2930
GroupAddr([u8; 6]),
@@ -498,6 +499,7 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for InfoBridge {
498499
}
499500

500501
#[derive(Debug, Clone, Eq, PartialEq)]
502+
#[non_exhaustive]
501503
pub enum BridgeQuerierState {
502504
Ipv4Address(Ipv4Addr),
503505
Ipv4Port(u32),

0 commit comments

Comments
 (0)