macro_rules! strwriter_as_str {
    ($expr:expr) => { ... };
}
👎Deprecated since 0.2.19: Use StrWriter::as_str_alt instead
Available on crate feature fmt only.
Expand description

Converts a &'static StrWriter to a &'static str, in a const/static initializer.

This is usable in const or static initializers, but not inside of const fns.

Deprecated: This macro is deprecated because the StrWriter::as_str_alt method allows converting a&'static StrWriter to a &'static str.

Runtime

If the “rust_1_64” feature is disabled, this takes time proportional to $expr.capacity() - $expr.len().

If the “rust_1_64” feature is enabled, it takes constant time to run.

Example

#![feature(const_mut_refs)]

use const_format::StrWriter;
use const_format::{strwriter_as_str, unwrap, writec};


const CAP: usize = 128;

const __STR: &StrWriter = &{
    let mut writer =  StrWriter::new([0; CAP]);

    // Writing the array with debug formatting, and the integers with hexadecimal formatting.
    unwrap!(writec!(writer, "{:x}", [3u32, 5, 8, 13, 21, 34]));

    writer
};

const STR: &str = strwriter_as_str!(__STR);

fn main() {
    assert_eq!(STR, "[3, 5, 8, d, 15, 22]");
}