macro_rules! tokenize_core_fmt_to_buffer {
    ($buffer:expr, $($format_string:literal)PW_FMT_CONCAT+ $(, $args:expr)* $(,)?) => { ... };
}
Expand description

Tokenize a core::fmt style format string and arguments to an AsMut<u8> buffer. The format string is converted in to a printf and added token to the token database.

See token for an explanation on how strings are tokenized and entries are added to the token database. The token’s domain is set to "".

Returns a pw_status::Result<usize> the number of bytes written to the buffer.

tokenize_to_buffer! supports concatenation of format strings as described in pw_format::macros::FormatAndArgs.

§Errors

§Example

use pw_tokenizer::tokenize_core_fmt_to_buffer;

// Tokenize a format string and argument into a buffer.
let mut buffer = [0u8; 1024];
let len = tokenize_core_fmt_to_buffer!(&mut buffer, "The answer is {}", 42 as i32)?;

// 4 bytes used to encode the token and one to encode the value 42.
assert_eq!(len, 5);

// The format string can be composed of multiple strings literals using
// the custom`PW_FMT_CONCAT` operator.
let len = tokenize_core_fmt_to_buffer!(&mut buffer, "Hello " PW_FMT_CONCAT "Pigweed")?;

// Only a single 4 byte token is emitted after concatenation of the string
// literals above.
assert_eq!(len, 4);