strprintf 0.1.0

Provide a way to interpolate printf-style format strings using native Rust types. Part of libnewsboat lib dependencies
Documentation
  • Coverage
  • 75%
    12 out of 16 items documented0 out of 4 items with examples
  • Size
  • Source code size: 13.05 MB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.87 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • newsboat/newsboat
    3738 234 391
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Minoru exaroth

Strprintf

This project is part of Newsboat Rust libraries, I'm not it's author - merely maintaining up to date versions on Crates.io.

Description

Problem statement for strprintf crate: provide a way to interpolate printf-style format strings using native Rust types. For example, it should be possible to format a string "%i %.2f %x" using values 42u32, 3.1415f64, and 255u8, and get a std::string::String "42 3.14 ff".

This is the same as strprintf module we already have in C++.

The problem can be solved by wrapping libc::snprintf, which is what we do both here and in C++. However, our experience with C++ showed that we should constrain what types can be formatted. Otherwise, complex objects like String will be passed over FFI and lead to unexpected results (e.g. garbage strings).

To achieve that, we provide a Printfable trait that's implemented only for types that our formatting macro accepts. Everything else will result in a compile-time error. See the docs in trait module for more on that.