[][src]Macro const_format::unwrap

macro_rules! unwrap {
    ($e:expr $(,)*) => { ... };
}
This is supported on crate feature fmt only.

Equivalent to Result::unwrap, for use with const_format::Error errors.

You can use this when you know for certain that no error will happen.

Example

#![feature(const_mut_refs)]

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

const CAP: usize = 11;
// Defined this function as a workaround for mutable references not
// being allowed in `const`ants.
const fn foo() -> StrWriter<[u8; CAP]> {
    let mut writer = StrWriter::new([0; CAP]);
    unwrap!(writec!(writer, "foo bar baz"));
    writer
}

const TEXT: &str = {
    const S: &StrWriter = &foo();
    strwriter_as_str!(S)
};
assert_eq!(TEXT, "foo bar baz")