Skip to content

Commit

Permalink
impl Format for NonZero*
Browse files Browse the repository at this point in the history
  • Loading branch information
Urhengulas committed Jun 16, 2021
1 parent 19f92c5 commit 4284704
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
14 changes: 13 additions & 1 deletion firmware/qemu/src/bin/log.out
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,16 @@
0.000124 INFO ChunksExact(..)
0.000125 INFO Iter { slice: [0, 1, 2], position: ? }
0.000126 INFO Windows(..)
0.000127 INFO QEMU test finished!
0.000127 INFO 1
0.000128 INFO 1
0.000129 INFO 1
0.000130 INFO 1
0.000131 INFO 1
0.000132 INFO 1
0.000133 INFO 1
0.000134 INFO 1
0.000135 INFO 1
0.000136 INFO 1
0.000137 INFO 1
0.000138 INFO 1
0.000139 INFO QEMU test finished!
14 changes: 13 additions & 1 deletion firmware/qemu/src/bin/log.release.out
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,16 @@
0.000122 INFO ChunksExact(..)
0.000123 INFO Iter { slice: [0, 1, 2], position: ? }
0.000124 INFO Windows(..)
0.000125 INFO QEMU test finished!
0.000125 INFO 1
0.000126 INFO 1
0.000127 INFO 1
0.000128 INFO 1
0.000129 INFO 1
0.000130 INFO 1
0.000131 INFO 1
0.000132 INFO 1
0.000133 INFO 1
0.000134 INFO 1
0.000135 INFO 1
0.000136 INFO 1
0.000137 INFO QEMU test finished!
15 changes: 15 additions & 0 deletions firmware/qemu/src/bin/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use core::{
marker::PhantomData,
num,
sync::atomic::{AtomicU32, Ordering},
};
use cortex_m_rt::entry;
Expand Down Expand Up @@ -617,6 +618,20 @@ fn main() -> ! {
defmt::info!("{:?}", [0, 1, 2].iter()); // ChunksExact
defmt::info!("{:?}", [0, 1, 2].windows(1)); // Windows

// core::num::NonZero*
defmt::info!("{}", num::NonZeroI8::new(1).unwrap());
defmt::info!("{}", num::NonZeroI16::new(1).unwrap());
defmt::info!("{}", num::NonZeroI32::new(1).unwrap());
defmt::info!("{}", num::NonZeroI64::new(1).unwrap());
defmt::info!("{}", num::NonZeroI128::new(1).unwrap());
defmt::info!("{}", num::NonZeroIsize::new(1).unwrap());
defmt::info!("{}", num::NonZeroU8::new(1).unwrap());
defmt::info!("{}", num::NonZeroU16::new(1).unwrap());
defmt::info!("{}", num::NonZeroU32::new(1).unwrap());
defmt::info!("{}", num::NonZeroU64::new(1).unwrap());
defmt::info!("{}", num::NonZeroU128::new(1).unwrap());
defmt::info!("{}", num::NonZeroUsize::new(1).unwrap());

defmt::info!("QEMU test finished!");

loop {
Expand Down
1 change: 1 addition & 0 deletions src/impls/core_/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! We generally keep the type parameter trait bounds in case it becomes possible to use this
//! later, without making a backwards-incompatible change.

mod num;
mod ops;
mod slice;

Expand Down
26 changes: 26 additions & 0 deletions src/impls/core_/num.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use core::num;

use super::*;

macro_rules! non_zero {
($type:ty) => {
impl Format for $type {
fn format(&self, fmt: Formatter) {
crate::write!(fmt, "{}", self.get());
}
}
};
}

non_zero! {num::NonZeroI8}
non_zero! {num::NonZeroI16}
non_zero! {num::NonZeroI32}
non_zero! {num::NonZeroI64}
non_zero! {num::NonZeroI128}
non_zero! {num::NonZeroIsize}
non_zero! {num::NonZeroU8}
non_zero! {num::NonZeroU16}
non_zero! {num::NonZeroU32}
non_zero! {num::NonZeroU64}
non_zero! {num::NonZeroU128}
non_zero! {num::NonZeroUsize}

0 comments on commit 4284704

Please sign in to comment.