Skip to content

Commit 53a4c4e

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 2d1acce commit 53a4c4e

File tree

5 files changed

+6
-0
lines changed

5 files changed

+6
-0
lines changed

src/buffer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ pub const NETLINK_HEADER_LEN: usize = PAYLOAD.start;
103103
/// Note that in this second example we don't call
104104
/// [`new_checked()`](struct.NetlinkBuffer.html#method.new_checked) because the length field is
105105
/// initialized to 0, so `new_checked()` would return an error.
106+
#[non_exhaustive]
106107
pub struct NetlinkBuffer<T> {
107108
pub buffer: T,
108109
}

src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const PAYLOAD: Rest = 4..;
1212
const ERROR_HEADER_LEN: usize = PAYLOAD.start;
1313

1414
#[derive(Debug, PartialEq, Eq, Clone)]
15+
#[non_exhaustive]
1516
pub struct ErrorBuffer<T> {
1617
buffer: T,
1718
}
@@ -77,6 +78,7 @@ impl<T: AsRef<[u8]> + AsMut<[u8]>> ErrorBuffer<T> {
7778
}
7879

7980
#[derive(Debug, Clone, PartialEq, Eq)]
81+
#[non_exhaustive]
8082
pub struct ErrorMessage {
8183
pub code: i32,
8284
pub header: Vec<u8>,

src/header.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::{buffer::NETLINK_HEADER_LEN, Emitable, NetlinkBuffer, Parseable};
2020
/// +----------------+----------------+----------------+----------------+
2121
/// ```
2222
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Default)]
23+
#[non_exhaustive]
2324
pub struct NetlinkHeader {
2425
/// Length of the netlink packet, including the header and the payload
2526
pub length: u32,

src/message.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::{
1414

1515
/// Represent a netlink message.
1616
#[derive(Debug, PartialEq, Eq, Clone)]
17+
#[non_exhaustive]
1718
pub struct NetlinkMessage<I> {
1819
/// Message header (this is common to all the netlink protocols)
1920
pub header: NetlinkHeader,

src/payload.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub const NLMSG_OVERRUN: u16 = 4;
1616
pub const NLMSG_ALIGNTO: u16 = 4;
1717

1818
#[derive(Debug, PartialEq, Eq, Clone)]
19+
#[non_exhaustive]
1920
pub enum NetlinkPayload<I> {
2021
Done,
2122
Error(ErrorMessage),

0 commit comments

Comments
 (0)