Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: derive(defmt::Format) by additional feature #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand Down