Skip to content

Commit cf805eb

Browse files
feat: Add initial serde:{Deserialize, Serialize} implementation for Ipv[4|6]Cidr
1 parent 2e9a30a commit cf805eb

File tree

5 files changed

+7
-0
lines changed

5 files changed

+7
-0
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ bitflags = { version = "1.0", default-features = false }
2828
defmt = { version = "0.3.8", optional = true, features = ["ip_in_core"] }
2929
cfg-if = "1.0.0"
3030
heapless = "0.8"
31+
serde = { version = "1.0.217", default-features = false, features = ["derive"], optional = true }
3132

3233
[dev-dependencies]
3334
env_logger = "0.10"
@@ -41,6 +42,8 @@ std = ["managed/std", "alloc"]
4142
alloc = ["managed/alloc", "defmt?/alloc"]
4243
verbose = []
4344
defmt = ["dep:defmt", "heapless/defmt-03"]
45+
# Implement serde Serialize / Deserialize
46+
serde = ["dep:serde", "heapless/serde"]
4447
"medium-ethernet" = ["socket"]
4548
"medium-ip" = ["socket"]
4649
"medium-ieee802154" = ["socket", "proto-sixlowpan"]

src/socket/dhcpv4.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ enum ClientState {
115115
/// Timeout and retry configuration.
116116
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
117117
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
118+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
118119
#[non_exhaustive]
119120
pub struct RetryConfig {
120121
pub discover_timeout: Duration,

src/time.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ impl ops::Sub<Instant> for Instant {
178178

179179
/// A relative amount of time.
180180
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
181+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
181182
pub struct Duration {
182183
micros: u64,
183184
}

src/wire/ipv4.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ impl AddressExt for Address {
100100
/// A specification of an IPv4 CIDR block, containing an address and a variable-length
101101
/// subnet masking prefix length.
102102
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
103+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
103104
pub struct Cidr {
104105
address: Address,
105106
prefix_len: u8,

src/wire/ipv6.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ impl AddressExt for Address {
233233
/// A specification of an IPv6 CIDR block, containing an address and a variable-length
234234
/// subnet masking prefix length.
235235
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
236+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
236237
pub struct Cidr {
237238
address: Address,
238239
prefix_len: u8,

0 commit comments

Comments
 (0)