Trait netsblox_vm::compact_str::ToCompactString
source · pub trait ToCompactString {
// Required method
fn to_compact_string(&self) -> CompactString;
}Expand description
A trait for converting a value to a CompactString.
This trait is automatically implemented for any type which implements the
fmt::Display trait. As such, ToCompactString shouldn’t be implemented directly:
fmt::Display should be implemented instead, and you get the ToCompactString
implementation for free.
Required Methods§
sourcefn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
Converts the given value to a CompactString.
Examples
Basic usage:
use compact_str::ToCompactString;
let i = 5;
let five = CompactString::new("5");
assert_eq!(i.to_compact_string(), five);Implementors§
impl<T> ToCompactString for Twhere
T: Display,
Panics
In this implementation, the to_compact_string method panics if the Display implementation
returns an error. This indicates an incorrect Display implementation since
std::fmt::Write for CompactString never returns an error itself.
Note
We use the [castaway] crate to provide zero-cost specialization for several types, those are:
u8,u16,u32,u64,u128,usizei8,i16,i32,i64,i128,isizeNonZeroU*,NonZeroI*boolcharString,CompactStringf32,f64- For floats we use
ryucrate which sometimes provides different formatting than [std]
- For floats we use