fish-shell/printf
Stefan Boca dcddffd222
refactor: misc cleanup (#10998)
* refactor EnvVar: Arc<Box<[WString]>> -> Arc<[WString]>

* remove unnecessary `&mut` from EnvVar methods

* clippy: use eq_ignore_ascii_case instead of manual comparison

see https://rust-lang.github.io/rust-clippy/master/index.html#manual_ignore_case_cmp

* clippy: use `is_some_and` and `is_ok_and` instead of `map_or`

see https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or

* clippy: use `assert!()` instead of `assert_eq!()` with booleans
2025-01-04 19:49:44 -06:00
..
src refactor: misc cleanup (#10998) 2025-01-04 19:49:44 -06:00
Cargo.toml Improve the README of the printf crate 2024-09-23 11:16:42 -07:00
LICENSE Mark that our printf is licensed under MIT 2024-06-09 12:15:04 -07:00
README.md Improve the README of the printf crate 2024-09-23 11:16:42 -07:00

fish-printf

The printf implementation used in fish-shell, based on musl printf.

crates.io

Licensed under the MIT license.

Usage

Run cargo add fish-printf to add this crate to your Cargo.toml file.

Notes

fish-printf attempts to match the C standard for printf. It supports the following features:

  • Locale-specific formatting (decimal point, thousands separator, etc.)
  • Honors the current rounding mode.
  • Supports the %n modifier for counting characters written.

fish-printf does not support positional arguments, such as printf("%2$d", 1, 2).

Prefixes like l or ll are recognized, but only used for validating the format string. The size of integer values is taken from the argument type.

fish-printf can output to an std::fmt::Write object, or return a string.

For reasons related to fish-shell, fish-printf has a feature "widestring" which uses the widestring crate. This is off by default. If enabled, run cargo add widestring to add the widestring crate.

Examples

use fish_printf::sprintf;

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

// Append to an existing string.
let mut s = String::new();
sprintf!(=> &mut s, "%0.5g", 123456.0) // 1.2346e+05

See the crate documentation for additional examples.