Skip to content

Commit 16863c4

Browse files
authored
Merge pull request #235 from rslawson/main
Add impls for most `core::net` types.
2 parents ead86b9 + 648285c commit 16863c4

2 files changed

Lines changed: 100 additions & 0 deletions

File tree

source/postcard-schema/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ use-std = ["serde/std"]
8585
alloc = ["serde/alloc"]
8686
derive = ["postcard-derive"]
8787

88+
core-net = []
89+
8890
defmt-v0_3 = ["defmt_v0_3"]
8991
uuid-v1_0 = ["uuid_v1_0"]
9092
chrono-v0_4 = ["chrono_v0_4"]

source/postcard-schema/src/impls/builtins_nostd.rs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,101 @@ impl<T: Schema> Schema for RangeTo<T> {
142142
}]),
143143
};
144144
}
145+
146+
#[cfg_attr(docsrs, doc(cfg(feature = "core-net")))]
147+
impl Schema for core::net::Ipv4Addr {
148+
const SCHEMA: &'static DataModelType = &DataModelType::Struct {
149+
name: "Ipv4Addr",
150+
data: Data::Struct(&[&NamedField {
151+
name: "octets",
152+
ty: <[u8; 4]>::SCHEMA,
153+
}]),
154+
};
155+
}
156+
157+
#[cfg_attr(docsrs, doc(cfg(feature = "core-net")))]
158+
impl Schema for core::net::Ipv6Addr {
159+
const SCHEMA: &'static DataModelType = &DataModelType::Struct {
160+
name: "Ipv6Addr",
161+
data: Data::Struct(&[&NamedField {
162+
name: "octets",
163+
ty: <[u8; 16]>::SCHEMA,
164+
}]),
165+
};
166+
}
167+
168+
#[cfg_attr(docsrs, doc(cfg(feature = "core-net")))]
169+
impl Schema for core::net::IpAddr {
170+
const SCHEMA: &'static DataModelType = &DataModelType::Enum {
171+
name: "IpAddr",
172+
variants: &[
173+
&Variant {
174+
name: "V4",
175+
data: Data::Newtype(core::net::Ipv4Addr::SCHEMA),
176+
},
177+
&Variant {
178+
name: "V6",
179+
data: Data::Newtype(core::net::Ipv6Addr::SCHEMA),
180+
},
181+
],
182+
};
183+
}
184+
185+
#[cfg_attr(docsrs, doc(cfg(feature = "core-net")))]
186+
impl Schema for core::net::SocketAddrV4 {
187+
const SCHEMA: &'static DataModelType = &DataModelType::Struct {
188+
name: "SocketAddrV4",
189+
data: Data::Struct(&[
190+
&NamedField {
191+
name: "ip",
192+
ty: core::net::Ipv4Addr::SCHEMA,
193+
},
194+
&NamedField {
195+
name: "port",
196+
ty: u16::SCHEMA,
197+
},
198+
]),
199+
};
200+
}
201+
202+
#[cfg_attr(docsrs, doc(cfg(feature = "core-net")))]
203+
impl Schema for core::net::SocketAddrV6 {
204+
const SCHEMA: &'static DataModelType = &DataModelType::Struct {
205+
name: "SocketAddrV6",
206+
data: Data::Struct(&[
207+
&NamedField {
208+
name: "ip",
209+
ty: core::net::Ipv6Addr::SCHEMA,
210+
},
211+
&NamedField {
212+
name: "port",
213+
ty: u16::SCHEMA,
214+
},
215+
&NamedField {
216+
name: "flowinfo",
217+
ty: u32::SCHEMA,
218+
},
219+
&NamedField {
220+
name: "scope_id",
221+
ty: u32::SCHEMA,
222+
},
223+
]),
224+
};
225+
}
226+
227+
#[cfg_attr(docsrs, doc(cfg(feature = "core-net")))]
228+
impl Schema for core::net::SocketAddr {
229+
const SCHEMA: &'static DataModelType = &DataModelType::Enum {
230+
name: "SocketAddr",
231+
variants: &[
232+
&Variant {
233+
name: "V4",
234+
data: Data::Newtype(core::net::SocketAddrV4::SCHEMA),
235+
},
236+
&Variant {
237+
name: "V6",
238+
data: Data::Newtype(core::net::SocketAddrV6::SCHEMA),
239+
},
240+
],
241+
};
242+
}

0 commit comments

Comments
 (0)