12 releases

new 0.4.2 May 17, 2025
0.4.0 Dec 5, 2024
0.3.1 Jul 14, 2024
0.2.1 Feb 12, 2024
0.1.2 Nov 6, 2021

#30 in Template engine

Download history 4636/week @ 2025-02-01 4963/week @ 2025-02-08 5201/week @ 2025-02-15 4735/week @ 2025-02-22 6253/week @ 2025-03-01 6118/week @ 2025-03-08 4855/week @ 2025-03-15 6036/week @ 2025-03-22 5334/week @ 2025-03-29 7078/week @ 2025-04-05 5789/week @ 2025-04-12 5285/week @ 2025-04-19 5567/week @ 2025-04-26 5964/week @ 2025-05-03 5893/week @ 2025-05-10 4355/week @ 2025-05-17

22,750 downloads per month
Used in 13 crates (6 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

~195–620KB
~14K SLoC