File tree Expand file tree Collapse file tree 3 files changed +16
-8
lines changed
Expand file tree Collapse file tree 3 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,9 @@ hex-literal.workspace = true
3333default = [" std" ]
3434std = [" bytes/std" , " arrayvec?/std" ]
3535derive = [" dep:alloy-rlp-derive" ]
36+ # Enables `core::net::` implementations always instead of conditionally through `std`.
37+ # Requires Rust 1.77 or newer.
38+ core-net = []
3639
3740arrayvec = [" dep:arrayvec" ]
3841
Original file line number Diff line number Diff line change @@ -142,9 +142,12 @@ where
142142 }
143143}
144144
145- #[ cfg( feature = "std" ) ]
145+ #[ cfg( any ( feature = "std" , feature = "core-net" ) ) ]
146146mod std_impl {
147147 use super :: * ;
148+ #[ cfg( all( feature = "core-net" , not( feature = "std" ) ) ) ]
149+ use core:: net:: { IpAddr , Ipv4Addr , Ipv6Addr } ;
150+ #[ cfg( feature = "std" ) ]
148151 use std:: net:: { IpAddr , Ipv4Addr , Ipv6Addr } ;
149152
150153 impl Decodable for IpAddr {
@@ -175,6 +178,11 @@ mod std_impl {
175178 slice_to_array :: < 16 > ( bytes) . map ( Self :: from)
176179 }
177180 }
181+
182+ #[ inline]
183+ fn slice_to_array < const N : usize > ( slice : & [ u8 ] ) -> Result < [ u8 ; N ] > {
184+ slice. try_into ( ) . map_err ( |_| Error :: UnexpectedLength )
185+ }
178186}
179187
180188/// Decodes the entire input, ensuring no trailing bytes remain.
@@ -223,12 +231,6 @@ pub(crate) fn static_left_pad<const N: usize>(data: &[u8]) -> Result<[u8; N]> {
223231 Ok ( v)
224232}
225233
226- #[ cfg( feature = "std" ) ]
227- #[ inline]
228- fn slice_to_array < const N : usize > ( slice : & [ u8 ] ) -> Result < [ u8 ; N ] > {
229- slice. try_into ( ) . map_err ( |_| Error :: UnexpectedLength )
230- }
231-
232234#[ cfg( test) ]
233235mod tests {
234236 use super :: * ;
Original file line number Diff line number Diff line change @@ -237,9 +237,12 @@ deref_impl! {
237237 [ T : ?Sized + Encodable ] alloc:: sync:: Arc <T >,
238238}
239239
240- #[ cfg( feature = "std" ) ]
240+ #[ cfg( any ( feature = "std" , feature = "core-net" ) ) ]
241241mod std_support {
242242 use super :: * ;
243+ #[ cfg( all( feature = "core-net" , not( feature = "std" ) ) ) ]
244+ use core:: net:: { IpAddr , Ipv4Addr , Ipv6Addr } ;
245+ #[ cfg( feature = "std" ) ]
243246 use std:: net:: { IpAddr , Ipv4Addr , Ipv6Addr } ;
244247
245248 impl Encodable for IpAddr {
You can’t perform that action at this time.
0 commit comments