Skip to main content

sprintf_locale

Function sprintf_locale 

Source
pub fn sprintf_locale<W: IoWrite + ?Sized>(
    f: &mut W,
    fmt: &BStr,
    locale: &Locale,
    args: &mut [Arg<'_>],
) -> Result<usize, Error>
Expand description

Formats a byte string using the provided format specifiers, arguments, and locale.

§Parameters

  • f: The receiver of formatted output.
  • fmt: The format string being parsed.
  • locale: The locale to use for number formatting.
  • args: Iterator over the arguments to format.

§Returns

A Result which is Ok containing the number of bytes written on success, or an Error.

§Example

use luau_printf::{locale, sprintf_locale, ToArg};

let mut output = Vec::new();
let fmt = luau_printf::BStr::new("%'0.2f");
let mut args = [1234567.89_f64.to_arg()];

let result = sprintf_locale(&mut output, fmt, &locale::EN_US_LOCALE, &mut args);

assert_eq!(result, Ok(12));
assert_eq!(output.as_slice(), b"1,234,567.89");