API reference

aster_blueprint::numfmt

Pre-1.0: signatures are not frozen. Generated from rustdoc JSON of the compiled crate; rustdoc JSON format version 60. Only public items are listed.

Deterministic number formatting for UI text. There is no ambient locale: the functions use ASCII separators (, thousands, . decimal) and a [Locale] you pass in swaps them (Locale::de().apply(&fixed_grouped(..))).

Every function is pure and uses only ASCII separators (, thousands, . decimal) plus the ▲/▼ delta glyphs. Rounding is Rust's {:.N} (exact binary value, ties-to-even), so identical inputs give byte-identical text. Non-finite floats render as NaN, inf, -inf; -0 never appears.

use aster_blueprint::numfmt::*;
assert_eq!(thousands(1234567), "1,234,567");
assert_eq!(fixed(6.18034, 2), "6.18");
assert_eq!(percent(0.256, 1), "25.6%");
assert_eq!(duration_ms(65_000.), "1m 05s");
assert_eq!(bytes(1_500_000), "1.5 MB");
assert_eq!(delta_pct(112., 100., 1), "▲ 12.0%");

Structs

structaster_blueprint::numfmt::Locale

pub struct Locale { /* see fields */ }

The separators of a language: what , (thousands) and . (decimal) become, and the space before %. Chosen by the app (nothing reads the environment), applied to any string the functions above return.

Public fields

fieldtype
group&'static str
decimal&'static str
percent_gap&'static strWritten between a number and % (empty in English, a no-break space in French and German).

Methods

  • const fn new(group: &'static str, decimal: &'static str) -> Self
  • const fn en() -> Self — 1,234.5 (the default of every function here).
  • const fn de() -> Self — 1.234,5 and 25 % (German; Locale::es() is the same separators without the gap).
  • const fn fr() -> Self — 1 234,5 with a narrow no-break space, and 25 %.
  • const fn es() -> Self — 1.234,5 with no gap before % (Spanish, Italian, Portuguese, Dutch).
  • const fn ch() -> Self — 1’234.5 (Swiss).
  • const fn percent_gap(self, gap: &'static str) -> Self
  • fn apply(&self, s: &str) -> String — s (as returned by the functions of this module) with this locale's separators: , becomes the group separator, . the decimal one, and a % gets the gap before it. Text of the other kinds (1m 05s, ms) has neither and is unchanged; a . in a unit-less word is not expected here.

Trait implementations: Clone, Copy, Debug, Eq, PartialEq, StructuralPartialEq

Functions

fnaster_blueprint::numfmt::arrow

pub fn arrow(diff: f64) -> char

Direction glyph for a signed change: ▲ up, ▼ down, – no change.

fnaster_blueprint::numfmt::bytes

pub fn bytes(n: u64) -> String

Decimal byte sizes (1 KB = 1000 B): 512 B, 1.5 KB, 2.0 GB.

fnaster_blueprint::numfmt::bytes_bin

pub fn bytes_bin(n: u64) -> String

Binary byte sizes (1 KiB = 1024 B): 1.5 KiB, 3.0 MiB.

fnaster_blueprint::numfmt::compact

pub fn compact(v: f64) -> String

Compact magnitude: 999 -> "999", 1_500 -> "1.5K", 2_300_000 -> "2.3M".

fnaster_blueprint::numfmt::compact_in

pub fn compact_in(v: f64, loc: &Locale) -> String

[compact] in loc (1,5K in German; the K / M / B / T suffixes stay).

fnaster_blueprint::numfmt::delta_abs

pub fn delta_abs(diff: f64, decimals: usize) -> String

Absolute signed change with glyph: delta_abs(5., 2) -> ▲ 5.00.

fnaster_blueprint::numfmt::delta_pct

pub fn delta_pct(current: f64, previous: f64, decimals: usize) -> String

Relative change of current vs previous: ▲ 12.5%, ▼ 3.0%, – 0.0%. A zero (or non-finite) baseline has no relative change: n/a. Fonts without ▲ ▼ (e.g. Martian Mono) need [delta_pct_ascii].

fnaster_blueprint::numfmt::delta_pct_ascii

pub fn delta_pct_ascii(current: f64, previous: f64, decimals: usize) -> String

[delta_pct] with ASCII glyphs: +12.5%, -3.0%, 0.0%.

fnaster_blueprint::numfmt::delta_pct_with

pub fn delta_pct_with(current: f64, previous: f64, decimals: usize, glyphs: [char; 3]) -> String

[delta_pct] with caller glyphs [up, down, flat].

fnaster_blueprint::numfmt::duration_ms

pub fn duration_ms(ms: f64) -> String

Duration from milliseconds, compact: 850ms, 1.5s, 12s, 2m 05s, 1h 02m, 2d 03h. Negative values get a leading -.

fnaster_blueprint::numfmt::duration_s

pub fn duration_s(s: f64) -> String

Duration from seconds (see [duration_ms]).

fnaster_blueprint::numfmt::fixed

pub fn fixed(v: f64, decimals: usize) -> String

Fixed decimals: fixed(6.18034, 2) -> "6.18"; fixed(-0.001, 2) -> "0.00".

fnaster_blueprint::numfmt::fixed_grouped

pub fn fixed_grouped(v: f64, decimals: usize) -> String

Fixed decimals with thousands separators: 1234567.891, 2 -> "1,234,567.89".

fnaster_blueprint::numfmt::fixed_grouped_in

pub fn fixed_grouped_in(v: f64, decimals: usize, loc: &Locale) -> String

[fixed_grouped] in loc.

fnaster_blueprint::numfmt::fixed_in

pub fn fixed_in(v: f64, decimals: usize, loc: &Locale) -> String

[fixed] in loc (no grouping).

fnaster_blueprint::numfmt::fixed_sig

pub fn fixed_sig(v: f64, sig: usize) -> String

sig significant digits (at least 0 decimals, at most 8): small values keep their digits instead of rounding to zero. fixed_sig(0.02, 2) -> "0.02", fixed_sig(6.43, 2) -> "6.4", fixed_sig(128.4, 2) -> "128", 0 -> "0".

fnaster_blueprint::numfmt::percent

pub fn percent(ratio: f64, decimals: usize) -> String

A ratio as a percentage: percent(0.256, 1) -> "25.6%".

fnaster_blueprint::numfmt::percent_in

pub fn percent_in(ratio: f64, decimals: usize, loc: &Locale) -> String

[percent] in loc.

fnaster_blueprint::numfmt::signed

pub fn signed(v: f64, decimals: usize) -> String

Always-signed fixed decimals: +1.5, -1.5, 0.0 (zero has no sign).

fnaster_blueprint::numfmt::thousands

pub fn thousands(n: i64) -> String

1234567 -> "1,234,567"; -1000 -> "-1,000".

fnaster_blueprint::numfmt::thousands_in

pub fn thousands_in(n: i64, loc: &Locale) -> String

[thousands] in loc.

fnaster_blueprint::numfmt::thousands_with

pub fn thousands_with(n: i64, sep: &str) -> String

As [thousands] with a custom separator (e.g. "_" or "\u{202f}").