Macro from_utf8

Source
macro_rules! from_utf8 {
    ($slice:expr) => { ... };
}
Expand description

A const equivalent of std::str::from_utf8, usable *only in consts and statics.

* This can be only used in const fns when the "rust_1_55" feature is enabled.

For an equivalent function, which requires Rust 1.55.0 (while this macro only requires Rust 1.46.0) and the "rust_1_55" crate feature, there is the from_utf8 function.

ยงExample

use konst::{string, unwrap_ctx};

const OK: &str = unwrap_ctx!(string::from_utf8!(b"foo bar"));
assert_eq!(OK, "foo bar");

const ERR: Result<&str, string::Utf8Error> = string::from_utf8!(b"what\xFA");
assert_eq!(ERR.unwrap_err().valid_up_to(), 4);