Struct compile_fmt::Ascii
source · pub struct Ascii<'a>(/* private fields */);
Expand description
ASCII string wrapper.
This wrapper is useful for non-constant strings if it can be ensured that a string consists
entirely of ASCII chars. This allows decreasing capacity requirements for CompileArgs
involving such strings. In the general case, CompileArgs
logic must assume that each char
in a string can require up to 4 bytes; in case of Ascii
strings, this is reduced to
1 byte per char.
Examples
use compile_fmt::{clip, clip_ascii, compile_args, Ascii, CompileArgs};
let s: CompileArgs<10> = compile_args!(
"[", Ascii::new("test") => clip_ascii(8, "").pad_left(8, ' '), "]"
);
assert_eq!(s.as_str(), "[test ]");
// The necessary capacity for generic UTF-8 strings is greater
// (34 bytes instead of 10):
let s: CompileArgs<34> = compile_args!(
"[", "test" => clip(8, "").pad_left(8, ' '), "]"
);
assert_eq!(s.as_str(), "[test ]");
Implementations§
Trait Implementations§
source§impl FormatArgument for Ascii<'_>
impl FormatArgument for Ascii<'_>
source§impl<'a> PartialEq for Ascii<'a>
impl<'a> PartialEq for Ascii<'a>
impl<'a> Copy for Ascii<'a>
impl<'a> Eq for Ascii<'a>
impl<'a> StructuralEq for Ascii<'a>
impl<'a> StructuralPartialEq for Ascii<'a>
Auto Trait Implementations§
impl<'a> RefUnwindSafe for Ascii<'a>
impl<'a> Send for Ascii<'a>
impl<'a> Sync for Ascii<'a>
impl<'a> Unpin for Ascii<'a>
impl<'a> UnwindSafe for Ascii<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more