Macro avr_progmem::progmem_str
source · macro_rules! progmem_str { ($text:expr) => { ... }; }
Expand description
Define a single-use string in progmem usable as temporary &str
This is a short-cut macro to create an ad-hoc static storing the given
string literal as by LoadedString
and load it here from progmem into a
temporary and return it as &str
.
This is similar to the F
macro available in Arduino.
Similar to the C marco, this will load the full string into RAM at once and thus the string should be of limited size, to not exceed the space available in RAM. Also see the progmem_display macro which does not have this limitation.
This macro allows to conveniently put a literal string into progmem
right where it is used.
However, since they are directly loaded into a temporary you don’t get a
&'static str
back, and must use the &str
immediately (i.e. pass it as a
function parameter).
You can’t even store the returned &str
in a local let
assignment.
Example
use avr_progmem::progmem_str as F;
use ufmt::uWrite;
let mut writer = // impl uWrite
/* SNIP */;
// Put the literal `str` into progmem and load it here as `&str`
writer.write_str(F!("dai 大賢者 kenja"));