luau-printf
Musl snprintf-compatible narrow byte formatting for Luau, forked from
fish-printf.
Licensed under the MIT license.
Usage
Add the crate dependency:
= "0.732.0"
Notes
luau-printf implements the musl snprintf narrow-conversion mechanics used by
Luau over safe Rust byte inputs and output sinks. It supports the following
features:
- Locale-specific formatting (decimal point, thousands separator, etc.)
- Honors the current rounding mode.
- Supports the
%nmodifier using narrowprintfoutput counts.
luau-printf does not support positional arguments, such as printf("%2$d", 1, 2).
Wide-character conversions such as %C, %S, %lc, and %ls are rejected;
Luau's source formatting paths do not use them.
Integer prefixes like h, l, or ll are recognized for supported integer
conversions, but only used for validating the format string. The size of
integer values is taken from the argument type.
luau-printf returns owned output as BString, writes to std::io::Write
sinks, and accepts byte-string format strings and %s arguments through BStr.
These byte slices are treated as bounded C-string views where snprintf expects
strings: format parsing and %s conversion stop at the first NUL byte.
Examples
use sprintf;
// Create a `BString` from a format string.
let s = sprintf!;
assert_eq!;
// Write to an existing byte sink.
let mut s = Vecnew;
sprintf!;
assert_eq!;
See the crate documentation for additional examples.