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

Tokenize a printf format string and arguments to an AsMut<u8> buffer and add the format string’s 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_printf_to_buffer;

// Tokenize a format string and argument into a buffer.
let mut buffer = [0u8; 1024];
let len = tokenize_printf_to_buffer!(&mut buffer, "The answer is %d", 42)?;

// 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_printf_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);