pub trait PrimitiveNumBuffer:
'static
+ Sealed
+ Debug
+ Send
+ Sized
+ Sync
+ Unpin
+ RefUnwindSafe
+ UnwindSafe {
// Required method
fn new() -> Self;
}Expand description
Trait for NumBuffer<T> for the decimal formatting of a primitive integer type.
In particular, this is used as a bound for the associated type PrimitiveInteger::NumBuffer,
passed as an argument to the format_into method. The main
use for this trait is just to create a buffer with new.
This trait is sealed with a private trait to prevent downstream implementations, so we may continue to expand along with the standard library without worrying about breaking changes for implementors.
§Examples
use num_primitive::{PrimitiveInteger, PrimitiveNumBuffer};
fn check_format_into<T: PrimitiveInteger>(x: T) {
assert!(size_of::<T::NumBuffer>() > size_of::<T>());
let mut buf = T::NumBuffer::new();
assert_eq!(x.format_into(&mut buf), x.to_string());
// Note that the buffer can be reused for multiple calls.
assert_eq!(T::default().format_into(&mut buf), "0");
assert_eq!(T::as_from(1).format_into(&mut buf), "1");
assert_eq!(T::MIN.format_into(&mut buf), T::MIN.to_string());
assert_eq!(T::MAX.format_into(&mut buf), T::MAX.to_string());
}
check_format_into(123_u64);
check_format_into(-42_i32);
assert!(size_of::<<u64 as PrimitiveInteger>::NumBuffer>()
> size_of::<<i32 as PrimitiveInteger>::NumBuffer>());Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".