diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-06-07 00:10:54 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-06-07 00:16:39 +0200 |
| commit | e7dc5c0939d30ccba98418c42799c4e39f646d23 (patch) | |
| tree | 896ebf078e97f15443dd85342f498231e142f975 /embassy-net | |
| parent | 4dda7be96841430c3aed2f014644b0b65cff0ef2 (diff) | |
fmt: make all macros `macro_rules` so scoping is consistent.
Diffstat (limited to 'embassy-net')
| -rw-r--r-- | embassy-net/src/config/dhcp.rs | 1 | ||||
| -rw-r--r-- | embassy-net/src/config/mod.rs | 1 | ||||
| -rw-r--r-- | embassy-net/src/config/statik.rs | 1 | ||||
| -rw-r--r-- | embassy-net/src/device.rs | 1 | ||||
| -rw-r--r-- | embassy-net/src/fmt.rs | 195 | ||||
| -rw-r--r-- | embassy-net/src/stack.rs | 1 | ||||
| -rw-r--r-- | embassy-net/src/tcp_socket.rs | 1 |
7 files changed, 146 insertions, 55 deletions
diff --git a/embassy-net/src/config/dhcp.rs b/embassy-net/src/config/dhcp.rs index f0c144321..8bbcd8176 100644 --- a/embassy-net/src/config/dhcp.rs +++ b/embassy-net/src/config/dhcp.rs | |||
| @@ -4,7 +4,6 @@ use smoltcp::time::Instant; | |||
| 4 | 4 | ||
| 5 | use super::*; | 5 | use super::*; |
| 6 | use crate::device::LinkState; | 6 | use crate::device::LinkState; |
| 7 | use crate::fmt::*; | ||
| 8 | use crate::{Interface, SocketSet}; | 7 | use crate::{Interface, SocketSet}; |
| 9 | 8 | ||
| 10 | pub struct DhcpConfigurator { | 9 | pub struct DhcpConfigurator { |
diff --git a/embassy-net/src/config/mod.rs b/embassy-net/src/config/mod.rs index 94725dba6..0f1886ae8 100644 --- a/embassy-net/src/config/mod.rs +++ b/embassy-net/src/config/mod.rs | |||
| @@ -2,7 +2,6 @@ use heapless::Vec; | |||
| 2 | use smoltcp::time::Instant; | 2 | use smoltcp::time::Instant; |
| 3 | use smoltcp::wire::{Ipv4Address, Ipv4Cidr}; | 3 | use smoltcp::wire::{Ipv4Address, Ipv4Cidr}; |
| 4 | 4 | ||
| 5 | use crate::fmt::*; | ||
| 6 | use crate::{Interface, SocketSet}; | 5 | use crate::{Interface, SocketSet}; |
| 7 | 6 | ||
| 8 | mod statik; | 7 | mod statik; |
diff --git a/embassy-net/src/config/statik.rs b/embassy-net/src/config/statik.rs index 912143bff..9a530717b 100644 --- a/embassy-net/src/config/statik.rs +++ b/embassy-net/src/config/statik.rs | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | use smoltcp::time::Instant; | 1 | use smoltcp::time::Instant; |
| 2 | 2 | ||
| 3 | use super::*; | 3 | use super::*; |
| 4 | use crate::fmt::*; | ||
| 5 | use crate::{Interface, SocketSet}; | 4 | use crate::{Interface, SocketSet}; |
| 6 | 5 | ||
| 7 | pub struct StaticConfigurator { | 6 | pub struct StaticConfigurator { |
diff --git a/embassy-net/src/device.rs b/embassy-net/src/device.rs index 6c06b0605..5fcb94ac8 100644 --- a/embassy-net/src/device.rs +++ b/embassy-net/src/device.rs | |||
| @@ -3,7 +3,6 @@ use smoltcp::phy::Device as SmolDevice; | |||
| 3 | use smoltcp::phy::DeviceCapabilities; | 3 | use smoltcp::phy::DeviceCapabilities; |
| 4 | use smoltcp::time::Instant as SmolInstant; | 4 | use smoltcp::time::Instant as SmolInstant; |
| 5 | 5 | ||
| 6 | use crate::fmt::*; | ||
| 7 | use crate::packet_pool::PacketBoxExt; | 6 | use crate::packet_pool::PacketBoxExt; |
| 8 | use crate::Result; | 7 | use crate::Result; |
| 9 | use crate::{Packet, PacketBox, PacketBuf}; | 8 | use crate::{Packet, PacketBox, PacketBuf}; |
diff --git a/embassy-net/src/fmt.rs b/embassy-net/src/fmt.rs index 4da69766c..6c5063f7c 100644 --- a/embassy-net/src/fmt.rs +++ b/embassy-net/src/fmt.rs | |||
| @@ -1,74 +1,171 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | #![allow(unused_macros)] | ||
| 2 | 3 | ||
| 3 | #[cfg(all(feature = "defmt", feature = "log"))] | 4 | #[cfg(all(feature = "defmt", feature = "log"))] |
| 4 | compile_error!("You may not enable both `defmt` and `log` features."); | 5 | compile_error!("You may not enable both `defmt` and `log` features."); |
| 5 | 6 | ||
| 6 | pub use fmt::*; | 7 | macro_rules! assert { |
| 8 | ($($x:tt)*) => { | ||
| 9 | { | ||
| 10 | #[cfg(not(feature = "defmt"))] | ||
| 11 | core::assert!($($x)*); | ||
| 12 | #[cfg(feature = "defmt")] | ||
| 13 | defmt::assert!($($x)*); | ||
| 14 | } | ||
| 15 | }; | ||
| 16 | } | ||
| 7 | 17 | ||
| 8 | #[cfg(feature = "defmt")] | 18 | macro_rules! assert_eq { |
| 9 | mod fmt { | 19 | ($($x:tt)*) => { |
| 10 | pub use defmt::{ | 20 | { |
| 11 | assert, assert_eq, assert_ne, debug, debug_assert, debug_assert_eq, debug_assert_ne, error, | 21 | #[cfg(not(feature = "defmt"))] |
| 12 | info, panic, todo, trace, unreachable, unwrap, warn, | 22 | core::assert_eq!($($x)*); |
| 23 | #[cfg(feature = "defmt")] | ||
| 24 | defmt::assert_eq!($($x)*); | ||
| 25 | } | ||
| 13 | }; | 26 | }; |
| 14 | } | 27 | } |
| 15 | 28 | ||
| 16 | #[cfg(feature = "log")] | 29 | macro_rules! assert_ne { |
| 17 | mod fmt { | 30 | ($($x:tt)*) => { |
| 18 | pub use core::{ | 31 | { |
| 19 | assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, | 32 | #[cfg(not(feature = "defmt"))] |
| 20 | unreachable, | 33 | core::assert_ne!($($x)*); |
| 34 | #[cfg(feature = "defmt")] | ||
| 35 | defmt::assert_ne!($($x)*); | ||
| 36 | } | ||
| 21 | }; | 37 | }; |
| 22 | pub use log::{debug, error, info, trace, warn}; | ||
| 23 | } | 38 | } |
| 24 | 39 | ||
| 25 | #[cfg(not(any(feature = "defmt", feature = "log")))] | 40 | macro_rules! debug_assert { |
| 26 | mod fmt { | 41 | ($($x:tt)*) => { |
| 27 | #![macro_use] | 42 | { |
| 43 | #[cfg(not(feature = "defmt"))] | ||
| 44 | core::debug_assert!($($x)*); | ||
| 45 | #[cfg(feature = "defmt")] | ||
| 46 | defmt::debug_assert!($($x)*); | ||
| 47 | } | ||
| 48 | }; | ||
| 49 | } | ||
| 28 | 50 | ||
| 29 | pub use core::{ | 51 | macro_rules! debug_assert_eq { |
| 30 | assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, | 52 | ($($x:tt)*) => { |
| 31 | unreachable, | 53 | { |
| 54 | #[cfg(not(feature = "defmt"))] | ||
| 55 | core::debug_assert_eq!($($x)*); | ||
| 56 | #[cfg(feature = "defmt")] | ||
| 57 | defmt::debug_assert_eq!($($x)*); | ||
| 58 | } | ||
| 32 | }; | 59 | }; |
| 60 | } | ||
| 33 | 61 | ||
| 34 | #[macro_export] | 62 | macro_rules! debug_assert_ne { |
| 35 | macro_rules! trace { | 63 | ($($x:tt)*) => { |
| 36 | ($($msg:expr),+ $(,)?) => { | 64 | { |
| 37 | () | 65 | #[cfg(not(feature = "defmt"))] |
| 38 | }; | 66 | core::debug_assert_ne!($($x)*); |
| 39 | } | 67 | #[cfg(feature = "defmt")] |
| 68 | defmt::debug_assert_ne!($($x)*); | ||
| 69 | } | ||
| 70 | }; | ||
| 71 | } | ||
| 40 | 72 | ||
| 41 | #[macro_export] | 73 | macro_rules! todo { |
| 42 | macro_rules! debug { | 74 | ($($x:tt)*) => { |
| 43 | ($($msg:expr),+ $(,)?) => { | 75 | { |
| 44 | () | 76 | #[cfg(not(feature = "defmt"))] |
| 45 | }; | 77 | core::todo!($($x)*); |
| 46 | } | 78 | #[cfg(feature = "defmt")] |
| 79 | defmt::todo!($($x)*); | ||
| 80 | } | ||
| 81 | }; | ||
| 82 | } | ||
| 47 | 83 | ||
| 48 | #[macro_export] | 84 | macro_rules! unreachable { |
| 49 | macro_rules! info { | 85 | ($($x:tt)*) => { |
| 50 | ($($msg:expr),+ $(,)?) => { | 86 | { |
| 51 | () | 87 | #[cfg(not(feature = "defmt"))] |
| 52 | }; | 88 | core::unreachable!($($x)*); |
| 53 | } | 89 | #[cfg(feature = "defmt")] |
| 90 | defmt::unreachable!($($x)*); | ||
| 91 | } | ||
| 92 | }; | ||
| 93 | } | ||
| 54 | 94 | ||
| 55 | #[macro_export] | 95 | macro_rules! panic { |
| 56 | macro_rules! warn { | 96 | ($($x:tt)*) => { |
| 57 | ($($msg:expr),+ $(,)?) => { | 97 | { |
| 58 | () | 98 | #[cfg(not(feature = "defmt"))] |
| 59 | }; | 99 | core::panic!($($x)*); |
| 60 | } | 100 | #[cfg(feature = "defmt")] |
| 101 | defmt::panic!($($x)*); | ||
| 102 | } | ||
| 103 | }; | ||
| 104 | } | ||
| 61 | 105 | ||
| 62 | #[macro_export] | 106 | macro_rules! trace { |
| 63 | macro_rules! error { | 107 | ($($x:tt)*) => { |
| 64 | ($($msg:expr),+ $(,)?) => { | 108 | { |
| 65 | () | 109 | #[cfg(feature = "log")] |
| 66 | }; | 110 | log::trace!($($x)*); |
| 67 | } | 111 | #[cfg(feature = "defmt")] |
| 112 | defmt::trace!($($x)*); | ||
| 113 | } | ||
| 114 | }; | ||
| 115 | } | ||
| 116 | |||
| 117 | macro_rules! debug { | ||
| 118 | ($($x:tt)*) => { | ||
| 119 | { | ||
| 120 | #[cfg(fevature = "log")] | ||
| 121 | log::debug!($($x)*); | ||
| 122 | #[cfg(feature = "defmt")] | ||
| 123 | defmt::debug!($($x)*); | ||
| 124 | } | ||
| 125 | }; | ||
| 126 | } | ||
| 127 | |||
| 128 | macro_rules! info { | ||
| 129 | ($($x:tt)*) => { | ||
| 130 | { | ||
| 131 | #[cfg(feature = "log")] | ||
| 132 | log::info!($($x)*); | ||
| 133 | #[cfg(feature = "defmt")] | ||
| 134 | defmt::info!($($x)*); | ||
| 135 | } | ||
| 136 | }; | ||
| 137 | } | ||
| 138 | |||
| 139 | macro_rules! warn { | ||
| 140 | ($($x:tt)*) => { | ||
| 141 | { | ||
| 142 | #[cfg(feature = "log")] | ||
| 143 | log::warn!($($x)*); | ||
| 144 | #[cfg(feature = "defmt")] | ||
| 145 | defmt::warn!($($x)*); | ||
| 146 | } | ||
| 147 | }; | ||
| 148 | } | ||
| 149 | |||
| 150 | macro_rules! error { | ||
| 151 | ($($x:tt)*) => { | ||
| 152 | { | ||
| 153 | #[cfg(feature = "log")] | ||
| 154 | log::error!($($x)*); | ||
| 155 | #[cfg(feature = "defmt")] | ||
| 156 | defmt::error!($($x)*); | ||
| 157 | } | ||
| 158 | }; | ||
| 159 | } | ||
| 160 | |||
| 161 | #[cfg(feature = "defmt")] | ||
| 162 | macro_rules! unwrap { | ||
| 163 | ($($x:tt)*) => { | ||
| 164 | defmt::unwrap!($($x)*) | ||
| 165 | }; | ||
| 68 | } | 166 | } |
| 69 | 167 | ||
| 70 | #[cfg(not(feature = "defmt"))] | 168 | #[cfg(not(feature = "defmt"))] |
| 71 | #[macro_export] | ||
| 72 | macro_rules! unwrap { | 169 | macro_rules! unwrap { |
| 73 | ($arg:expr) => { | 170 | ($arg:expr) => { |
| 74 | match $crate::fmt::Try::into_result($arg) { | 171 | match $crate::fmt::Try::into_result($arg) { |
diff --git a/embassy-net/src/stack.rs b/embassy-net/src/stack.rs index e436beb1e..a38f00958 100644 --- a/embassy-net/src/stack.rs +++ b/embassy-net/src/stack.rs | |||
| @@ -20,7 +20,6 @@ use smoltcp::wire::{IpAddress, IpCidr, Ipv4Address, Ipv4Cidr}; | |||
| 20 | use crate::config::Configurator; | 20 | use crate::config::Configurator; |
| 21 | use crate::config::Event; | 21 | use crate::config::Event; |
| 22 | use crate::device::{Device, DeviceAdapter, LinkState}; | 22 | use crate::device::{Device, DeviceAdapter, LinkState}; |
| 23 | use crate::fmt::*; | ||
| 24 | use crate::{Interface, SocketSet}; | 23 | use crate::{Interface, SocketSet}; |
| 25 | 24 | ||
| 26 | const ADDRESSES_LEN: usize = 1; | 25 | const ADDRESSES_LEN: usize = 1; |
diff --git a/embassy-net/src/tcp_socket.rs b/embassy-net/src/tcp_socket.rs index 4f43bc611..def4c8176 100644 --- a/embassy-net/src/tcp_socket.rs +++ b/embassy-net/src/tcp_socket.rs | |||
| @@ -11,7 +11,6 @@ use smoltcp::time::Duration; | |||
| 11 | use smoltcp::wire::IpEndpoint; | 11 | use smoltcp::wire::IpEndpoint; |
| 12 | 12 | ||
| 13 | use super::stack::Stack; | 13 | use super::stack::Stack; |
| 14 | use crate::fmt::*; | ||
| 15 | use crate::{Error, Result}; | 14 | use crate::{Error, Result}; |
| 16 | 15 | ||
| 17 | pub struct TcpSocket<'a> { | 16 | pub struct TcpSocket<'a> { |
