|
@@ -17,7 +17,7 @@ const DIGITS: [u8; 10] = [b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8',
|
|
|
const TRUNCATED_SLICE: [u8; 3] = [b'.', b'.', b'.'];
|
|
const TRUNCATED_SLICE: [u8; 3] = [b'.', b'.', b'.'];
|
|
|
|
|
|
|
|
/// Byte representing a truncated log.
|
|
/// Byte representing a truncated log.
|
|
|
-const TRUCATED: u8 = b'@';
|
|
|
|
|
|
|
+const TRUNCATED: u8 = b'@';
|
|
|
|
|
|
|
|
/// An uninitialized byte.
|
|
/// An uninitialized byte.
|
|
|
const UNINIT_BYTE: MaybeUninit<u8> = MaybeUninit::uninit();
|
|
const UNINIT_BYTE: MaybeUninit<u8> = MaybeUninit::uninit();
|
|
@@ -68,7 +68,7 @@ impl<const BUFFER: usize> Logger<BUFFER> {
|
|
|
if BUFFER > 0 {
|
|
if BUFFER > 0 {
|
|
|
unsafe {
|
|
unsafe {
|
|
|
let last = self.buffer.get_unchecked_mut(BUFFER - 1);
|
|
let last = self.buffer.get_unchecked_mut(BUFFER - 1);
|
|
|
- last.write(TRUCATED);
|
|
|
|
|
|
|
+ last.write(TRUNCATED);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
@@ -299,7 +299,7 @@ macro_rules! impl_log_for_unsigned_integer {
|
|
|
if overflow {
|
|
if overflow {
|
|
|
unsafe {
|
|
unsafe {
|
|
|
let last = buffer.get_unchecked_mut(written - 1);
|
|
let last = buffer.get_unchecked_mut(written - 1);
|
|
|
- last.write(TRUCATED);
|
|
|
|
|
|
|
+ last.write(TRUNCATED);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
written
|
|
written
|
|
@@ -316,10 +316,15 @@ impl_log_for_unsigned_integer!(u16, 5);
|
|
|
impl_log_for_unsigned_integer!(u32, 10);
|
|
impl_log_for_unsigned_integer!(u32, 10);
|
|
|
impl_log_for_unsigned_integer!(u64, 20);
|
|
impl_log_for_unsigned_integer!(u64, 20);
|
|
|
impl_log_for_unsigned_integer!(u128, 39);
|
|
impl_log_for_unsigned_integer!(u128, 39);
|
|
|
|
|
+// Handle the `usize` type.
|
|
|
|
|
+#[cfg(target_pointer_width = "32")]
|
|
|
|
|
+impl_log_for_unsigned_integer!(usize, 10);
|
|
|
|
|
+#[cfg(target_pointer_width = "64")]
|
|
|
|
|
+impl_log_for_unsigned_integer!(usize, 20);
|
|
|
|
|
|
|
|
/// Implement the log trait for the signed integer types.
|
|
/// Implement the log trait for the signed integer types.
|
|
|
macro_rules! impl_log_for_signed {
|
|
macro_rules! impl_log_for_signed {
|
|
|
- ( $type:tt, $unsigned_type:tt, $max_digits:literal ) => {
|
|
|
|
|
|
|
+ ( $type:tt ) => {
|
|
|
impl Log for $type {
|
|
impl Log for $type {
|
|
|
#[inline]
|
|
#[inline]
|
|
|
fn write_with_args(&self, buffer: &mut [MaybeUninit<u8>], args: &[Argument]) -> usize {
|
|
fn write_with_args(&self, buffer: &mut [MaybeUninit<u8>], args: &[Argument]) -> usize {
|
|
@@ -335,7 +340,7 @@ macro_rules! impl_log_for_signed {
|
|
|
}
|
|
}
|
|
|
1
|
|
1
|
|
|
}
|
|
}
|
|
|
- mut value => {
|
|
|
|
|
|
|
+ value => {
|
|
|
let mut prefix = 0;
|
|
let mut prefix = 0;
|
|
|
|
|
|
|
|
if *self < 0 {
|
|
if *self < 0 {
|
|
@@ -343,11 +348,11 @@ macro_rules! impl_log_for_signed {
|
|
|
buffer.get_unchecked_mut(0).write(b'-');
|
|
buffer.get_unchecked_mut(0).write(b'-');
|
|
|
}
|
|
}
|
|
|
prefix += 1;
|
|
prefix += 1;
|
|
|
- value = -value
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
prefix
|
|
prefix
|
|
|
- + (value as $unsigned_type).write_with_args(&mut buffer[prefix..], args)
|
|
|
|
|
|
|
+ + $type::unsigned_abs(value)
|
|
|
|
|
+ .write_with_args(&mut buffer[prefix..], args)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -356,11 +361,12 @@ macro_rules! impl_log_for_signed {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Supported signed integer types.
|
|
// Supported signed integer types.
|
|
|
-impl_log_for_signed!(i8, u8, 3);
|
|
|
|
|
-impl_log_for_signed!(i16, u16, 5);
|
|
|
|
|
-impl_log_for_signed!(i32, u32, 10);
|
|
|
|
|
-impl_log_for_signed!(i64, u64, 19);
|
|
|
|
|
-impl_log_for_signed!(i128, u128, 39);
|
|
|
|
|
|
|
+impl_log_for_signed!(i8);
|
|
|
|
|
+impl_log_for_signed!(i16);
|
|
|
|
|
+impl_log_for_signed!(i32);
|
|
|
|
|
+impl_log_for_signed!(i64);
|
|
|
|
|
+impl_log_for_signed!(i128);
|
|
|
|
|
+impl_log_for_signed!(isize);
|
|
|
|
|
|
|
|
/// Implement the log trait for the &str type.
|
|
/// Implement the log trait for the &str type.
|
|
|
impl Log for &str {
|
|
impl Log for &str {
|
|
@@ -379,7 +385,7 @@ impl Log for &str {
|
|
|
|
|
|
|
|
match buffer.len() - offset {
|
|
match buffer.len() - offset {
|
|
|
0 => unsafe {
|
|
0 => unsafe {
|
|
|
- buffer.get_unchecked_mut(offset - 1).write(TRUCATED);
|
|
|
|
|
|
|
+ buffer.get_unchecked_mut(offset - 1).write(TRUNCATED);
|
|
|
},
|
|
},
|
|
|
_ => {
|
|
_ => {
|
|
|
unsafe {
|
|
unsafe {
|
|
@@ -487,7 +493,7 @@ impl Log for &str {
|
|
|
if truncated {
|
|
if truncated {
|
|
|
unsafe {
|
|
unsafe {
|
|
|
let last = buffer.get_unchecked_mut(length - 1);
|
|
let last = buffer.get_unchecked_mut(length - 1);
|
|
|
- last.write(TRUCATED);
|
|
|
|
|
|
|
+ last.write(TRUNCATED);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -532,7 +538,7 @@ macro_rules! impl_log_for_slice {
|
|
|
for value in self.iter() {
|
|
for value in self.iter() {
|
|
|
if offset >= length {
|
|
if offset >= length {
|
|
|
unsafe {
|
|
unsafe {
|
|
|
- buffer.get_unchecked_mut(length - 1).write(TRUCATED);
|
|
|
|
|
|
|
+ buffer.get_unchecked_mut(length - 1).write(TRUNCATED);
|
|
|
}
|
|
}
|
|
|
offset = length;
|
|
offset = length;
|
|
|
break;
|
|
break;
|
|
@@ -541,7 +547,7 @@ macro_rules! impl_log_for_slice {
|
|
|
if offset > 1 {
|
|
if offset > 1 {
|
|
|
if offset + 2 >= length {
|
|
if offset + 2 >= length {
|
|
|
unsafe {
|
|
unsafe {
|
|
|
- buffer.get_unchecked_mut(length - 1).write(TRUCATED);
|
|
|
|
|
|
|
+ buffer.get_unchecked_mut(length - 1).write(TRUNCATED);
|
|
|
}
|
|
}
|
|
|
offset = length;
|
|
offset = length;
|
|
|
break;
|
|
break;
|