luau-printf 0.732.0

Luau musl snprintf-compatible narrow byte formatting
Documentation
  • Coverage
  • 61.29%
    19 out of 31 items documented3 out of 7 items with examples
  • Size
  • Source code size: 118.46 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.37 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 4s Average build duration of successful builds.
  • all releases: 4s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • luau-rs/luau
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • pcbzzz

luau-printf

Musl snprintf-compatible narrow byte formatting for Luau, forked from fish-printf.

Licensed under the MIT license.

Usage

Add the crate dependency:

luau-printf = "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 %n modifier using narrow printf output 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 luau_printf::sprintf;

// Create a `BString` from a format string.
let s = sprintf!("%0.5g", 123456.0);
assert_eq!(s, "1.2346e+05");

// Write to an existing byte sink.
let mut s = Vec::new();
sprintf!(=> &mut s, "%0.5g", 123456.0);
assert_eq!(s, b"1.2346e+05");

See the crate documentation for additional examples.