Macro arcstr::literal[][src]

macro_rules! literal {
    ($text : expr) => { ... };
}
Expand description

Create a const ArcStr from a string literal. The resulting ArcStr require no heap allocation, can be freely cloned and used interchangeably with ArcStrs from the heap, and are effectively “free”.

The main downside is that it’s a macro. Eventually it may be doable as a const fn, which would be cleaner, but for now the drawbacks to this are not overwhelming, and the functionality it provides is very useful.

Usage

// Works in const:
const MY_ARCSTR: ArcStr = arcstr::literal!("testing testing");
assert_eq!(MY_ARCSTR, "testing testing");

// Or, just in normal expressions.
assert_eq!("Wow!", arcstr::literal!("Wow!"));

Another motivating use case is bundled files (eventually this will improve when arcstr::Substr is implemented):

use arcstr::ArcStr;
const VERY_IMPORTANT_FILE: ArcStr =
    arcstr::literal!(include_str!("./very-important.txt"));