aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/fmt.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-05-17 00:57:32 +0200
committerDario Nieuwenhuis <[email protected]>2021-05-17 00:57:32 +0200
commitbfc7f52e6dd7b5ad12fa1f09483fa60f2732ae0c (patch)
treee63684b0915e274b2a041d3f5b862eb1865f71c8 /embassy-stm32/src/fmt.rs
parent97b01f1c4799a66bc2af596bfc5138ccf919a6de (diff)
Remove stm32.
stm32 developemnt continues in the `stm32-neo` branch for now.
Diffstat (limited to 'embassy-stm32/src/fmt.rs')
-rw-r--r--embassy-stm32/src/fmt.rs114
1 files changed, 0 insertions, 114 deletions
diff --git a/embassy-stm32/src/fmt.rs b/embassy-stm32/src/fmt.rs
deleted file mode 100644
index 160642ccd..000000000
--- a/embassy-stm32/src/fmt.rs
+++ /dev/null
@@ -1,114 +0,0 @@
1#![macro_use]
2#![allow(clippy::module_inception)]
3#![allow(unused)]
4
5#[cfg(all(feature = "defmt", feature = "log"))]
6compile_error!("You may not enable both `defmt` and `log` features.");
7
8pub use fmt::*;
9
10#[cfg(feature = "defmt")]
11mod fmt {
12 pub use defmt::{
13 assert, assert_eq, assert_ne, debug, debug_assert, debug_assert_eq, debug_assert_ne, error,
14 info, panic, todo, trace, unreachable, unwrap, warn,
15 };
16}
17
18#[cfg(feature = "log")]
19mod fmt {
20 pub use core::{
21 assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo,
22 unreachable,
23 };
24 pub use log::{debug, error, info, trace, warn};
25}
26
27#[cfg(not(any(feature = "defmt", feature = "log")))]
28mod fmt {
29 #![macro_use]
30
31 pub use core::{
32 assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo,
33 unreachable,
34 };
35
36 macro_rules! trace {
37 ($($msg:expr),+ $(,)?) => {
38 ()
39 };
40 }
41
42 macro_rules! debug {
43 ($($msg:expr),+ $(,)?) => {
44 ()
45 };
46 }
47
48 macro_rules! info {
49 ($($msg:expr),+ $(,)?) => {
50 ()
51 };
52 }
53
54 macro_rules! warn {
55 ($($msg:expr),+ $(,)?) => {
56 ()
57 };
58 }
59
60 macro_rules! error {
61 ($($msg:expr),+ $(,)?) => {
62 ()
63 };
64 }
65}
66
67#[cfg(not(feature = "defmt"))]
68macro_rules! unwrap {
69 ($arg:expr) => {
70 match $crate::fmt::Try::into_result($arg) {
71 ::core::result::Result::Ok(t) => t,
72 ::core::result::Result::Err(e) => {
73 ::core::panic!("unwrap of `{}` failed: {:?}", ::core::stringify!($arg), e);
74 }
75 }
76 };
77 ($arg:expr, $($msg:expr),+ $(,)? ) => {
78 match $crate::fmt::Try::into_result($arg) {
79 ::core::result::Result::Ok(t) => t,
80 ::core::result::Result::Err(e) => {
81 ::core::panic!("unwrap of `{}` failed: {}: {:?}", ::core::stringify!($arg), ::core::format_args!($($msg,)*), e);
82 }
83 }
84 }
85}
86
87#[derive(Debug, Copy, Clone, Eq, PartialEq)]
88pub struct NoneError;
89
90pub trait Try {
91 type Ok;
92 type Error;
93 fn into_result(self) -> Result<Self::Ok, Self::Error>;
94}
95
96impl<T> Try for Option<T> {
97 type Ok = T;
98 type Error = NoneError;
99
100 #[inline]
101 fn into_result(self) -> Result<T, NoneError> {
102 self.ok_or(NoneError)
103 }
104}
105
106impl<T, E> Try for Result<T, E> {
107 type Ok = T;
108 type Error = E;
109
110 #[inline]
111 fn into_result(self) -> Self {
112 self
113 }
114}