diff --git a/Cargo.toml b/Cargo.toml index 66be539..4604153 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,13 +19,18 @@ travis-ci = { repository = "dunmatt/no-std-net" } [dependencies] serde = { version = "^1", default-features = false, optional = true } +defmt = { version = "0.3", default-features = false, optional = true} [dev-dependencies] serde_test = "^1" [features] +default = ["defmt"] + # Makes the library act as a facade to std::net types std = [] +# defmt impls +defmt = ["dep:defmt"] # Like `#![feature(ip)]`, see https://github.com/rust-lang/rust/issues/27709 unstable_ip = [] # Deprecated. Does nothing. diff --git a/src/addr.rs b/src/addr.rs index 6ef9f72..2d881d7 100644 --- a/src/addr.rs +++ b/src/addr.rs @@ -35,6 +35,7 @@ use super::{IpAddr, Ipv4Addr, Ipv6Addr}; /// assert_eq!(socket.is_ipv4(), true); /// ``` #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum SocketAddr { /// An IPv4 socket address. V4(SocketAddrV4), @@ -64,6 +65,7 @@ pub enum SocketAddr { /// assert_eq!(socket.port(), 8080); /// ``` #[derive(Copy)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct SocketAddrV4 { addr: Ipv4Addr, port: u16, @@ -92,6 +94,7 @@ pub struct SocketAddrV4 { /// assert_eq!(socket.port(), 8080); /// ``` #[derive(Copy)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct SocketAddrV6 { addr: Ipv6Addr, port: u16, diff --git a/src/ip.rs b/src/ip.rs index 96d76b6..c3a833b 100644 --- a/src/ip.rs +++ b/src/ip.rs @@ -67,6 +67,7 @@ pub enum IpAddr { /// assert_eq!(localhost.is_loopback(), true); /// ``` #[derive(Copy)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct Ipv4Addr { // Octets stored in transmit order. inner: [u8; 4], @@ -101,6 +102,7 @@ pub struct Ipv4Addr { /// assert_eq!(localhost.is_loopback(), true); /// ``` #[derive(Copy)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct Ipv6Addr { // Octets stored in transmit order. inner: [u8; 16],