File: README.md

package info (click to toggle)
fish 4.2.1-3.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,976 kB
  • sloc: python: 6,972; javascript: 1,407; sh: 1,009; xml: 411; ansic: 230; objc: 78; makefile: 20
file content (43 lines) | stat: -rw-r--r-- 1,476 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# fish-printf

The printf implementation used in [fish-shell](https://fishshell.com), based on musl printf.

[![crates.io](https://img.shields.io/crates/v/fish-printf.svg)](https://crates.io/crates/fish-printf)

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](https://crates.io/crates/widestring) crate. This is off by default. If enabled, run `cargo add widestring` to add the widestring crate.

### Examples

```rust
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.