13 releases

0.4.3 Oct 7, 2025
0.4.2 May 17, 2025
0.4.1 Apr 30, 2025
0.4.0 Dec 5, 2024
0.1.2 Nov 6, 2021

#45 in WebAssembly

Download history 8397/week @ 2025-10-25 7958/week @ 2025-11-01 8204/week @ 2025-11-08 8548/week @ 2025-11-15 8064/week @ 2025-11-22 9083/week @ 2025-11-29 9313/week @ 2025-12-06 9598/week @ 2025-12-13 6101/week @ 2025-12-20 4782/week @ 2025-12-27 10541/week @ 2026-01-03 8343/week @ 2026-01-10 9506/week @ 2026-01-17 9587/week @ 2026-01-24 9263/week @ 2026-01-31 8122/week @ 2026-02-07

37,602 downloads per month
Used in 15 crates (8 directly)

MIT license

35KB
772 lines

Libc s(n)printf clone written in Rust, so you can use printf-style formatting without a libc (e.g. in WebAssembly).

Note: You're probably better off using standard Rust string formatting instead of thie crate unless you specificaly need printf compatibility.

It follows the standard C semantics, except:

  • Locale-aware UNIX extensions (' and GNU’s I) are not supported.
  • %a/%A (hexadecimal floating point) are currently not implemented.
  • Length modifiers (h, l, etc.) are checked, but ignored. The passed type is used instead.

Usage example:

use sprintf::sprintf;
let s = sprintf!("%d + %d = %d\n", 3, 9, 3+9).unwrap();
assert_eq!(s, "3 + 9 = 12\n");

The types of the arguments are checked at runtime.


sprintf-rs

a clone of C sprintf in Rust

This crate was created out of a desire to provide C printf-style formatting in a WASM program, where there is no libc.

Note: You're probably better off using standard Rust string formatting instead of this crate unless you specificaly need printf compatibility.

This crate implements a dynamically type-checked function vsprintf and macro sprintf!.

Usage example:

use sprintf::sprintf;
let s = sprintf!("%d + %d = %d\n", 3, 9, 3+9).unwrap();
assert_eq!(s, "3 + 9 = 12\n");

libc is a dev dependency as it is used in the tests to compare results. std is used for some maths functions.

Dependencies

~155–560KB
~13K SLoC