CtString
std::meta::ctstring contains methods on the built-in CtString type which is
a compile-time, dynamically-sized string type. Compared to str<N> and fmtstr<N, T>,
CtString is useful because its size does not need to be specified in its type. This
can be used for formatting items at compile-time or general string handling in comptime
code.
Since fmtstrs can be converted into CtStrings, you can make use of their formatting
abilities in CtStrings by formatting in fmtstrs then converting the result to a CtString
afterward.
Traits
AsCtString
pub trait AsCtString {
comptime fn as_ctstring(self) -> CtString;
}
Converts an object into a compile-time string.
Implementations:
impl<let N: u32> AsCtString for str<N> { ... }
impl<let N: u32, T> AsCtString for fmtstr<N, T> { ... }
Methods
new
pub comptime fn new() -> Self {
Creates an empty CtString.
append_str
pub comptime fn append_str<let N: u32>(self, s: str<N>) -> Self {
Returns a new CtString with the given str appended onto the end.
append_fmtstr
pub comptime fn append_fmtstr<let N: u32, T>(self, s: fmtstr<N, T>) -> Self {
Returns a new CtString with the given fmtstr appended onto the end.
as_quoted_str
pub comptime fn as_quoted_str(self) -> Quoted {
Returns a quoted string literal from this string's contents.
There is no direct conversion from a CtString to a str<N> since
the size would not be known. To get around this, this function can
be used in combination with macro insertion (!) to insert this string
literal at this function's call site.
Example:
let my_ctstring = "foo bar".as_ctstring();
let my_str: str<7> = my_ctstring.as_quoted_str!();
assert_eq(crate::meta::type_of(my_str), quote { str<7> }.as_type());
Trait Implementations
impl Eq for CtString
impl Hash for CtString
impl Append for CtString