Skip to content

stdlib/fmtView source ↗

fmt

23 items · generated by scribe fromstdlib/fmt.fd· synced 2026-11-15

stdlib/fmt23 items

Contents

fmt_int

Format an i64 as a decimal string.

Example: assert_eq(fmt_int(-42), “-42”);

pub fn fmt_int(n: i64) -> str {

Parameters:

  • n: i64

Returns: str

Defined at line 21


fmt_int_width

Format an i64 with a minimum width, padded with spaces on the left.

Example: assert_eq(fmt_int_width(42, 5), ” 42”);

pub fn fmt_int_width(n: i64, width: i64) -> str {

Parameters:

  • n: i64
  • width: i64

Returns: str

Defined at line 29


fmt_int_zero_pad

Format an i64 with a minimum width, zero-padded on the left.

Example: assert_eq(fmt_int_zero_pad(42, 5), “00042”);

pub fn fmt_int_zero_pad(n: i64, width: i64) -> str {

Parameters:

  • n: i64
  • width: i64

Returns: str

Defined at line 38


fmt_int_signed

Format an i64 as a signed string with a ’+’ for positive numbers.

Example: assert_eq(fmt_int_signed(5), “+5”); assert_eq(fmt_int_signed(-5), “-5”);

pub fn fmt_int_signed(n: i64) -> str {

Parameters:

  • n: i64

Returns: str

Defined at line 48


fmt_hex

Format an i64 as a hex string (lowercase).

Example: assert_eq(fmt_hex(48879), “beef”);

pub fn fmt_hex(n: i64) -> str {

Parameters:

  • n: i64

Returns: str

Defined at line 59


fmt_hex_prefix

Format an i64 as a hex string with “0x” prefix.

Example: assert_eq(fmt_hex_prefix(255), “0xff”);

pub fn fmt_hex_prefix(n: i64) -> str {

Parameters:

  • n: i64

Returns: str

Defined at line 67


fmt_hex_width

Format an i64 as a hex string with minimum width (zero-padded).

Example: assert_eq(fmt_hex_width(10, 4), “000a”);

pub fn fmt_hex_width(n: i64, width: i64) -> str {

Parameters:

  • n: i64
  • width: i64

Returns: str

Defined at line 75


fmt_bin

Format an i64 as a binary string.

Example: assert_eq(fmt_bin(10), “1010”);

pub fn fmt_bin(n: i64) -> str {

Parameters:

  • n: i64

Returns: str

Defined at line 83


fmt_bin_prefix

Format an i64 as a binary string with “0b” prefix.

Example: assert_eq(fmt_bin_prefix(3), “0b11”);

pub fn fmt_bin_prefix(n: i64) -> str {

Parameters:

  • n: i64

Returns: str

Defined at line 91


fmt_octal

Format an i64 as an octal string.

Example: assert_eq(fmt_octal(8), “10”); assert_eq(fmt_octal(511), “777”);

pub fn fmt_octal(n: i64) -> str {

Parameters:

  • n: i64

Returns: str

Defined at line 100


fmt_float

Format an f64 with a specified number of decimal places. fmt_float(3.14159, 2) → “3.14”

Example: var s = fmt_float(3.14159, 2); println(s); assert_eq(s, “3.14”); assert_eq(fmt_float(-1.5, 1), “-1.5”);

pub fn fmt_float(f: f64, decimals: i64) -> str {

Parameters:

  • f: f64
  • decimals: i64

Returns: str

Defined at line 129


fmt_float_default

Format an f64 with default 2 decimal places.

Example: assert_eq(fmt_float_default(2.5), “2.50”);

pub fn fmt_float_default(f: f64) -> str {

Parameters:

  • f: f64

Returns: str

Defined at line 154


fmt_percent

Format an f64 as a percentage with specified decimals. fmt_percent(0.875, 1) → “87.5%”

Example: assert_eq(fmt_percent(0.875, 1), “87.5%”);

pub fn fmt_percent(f: f64, decimals: i64) -> str {

Parameters:

  • f: f64
  • decimals: i64

Returns: str

Defined at line 163


fmt_bool

Format a bool as “true” or “false”.

Example: assert_eq(fmt_bool(true), “true”);

pub fn fmt_bool(b: bool) -> str {

Parameters:

  • b: bool

Returns: str

Defined at line 173


fmt_yes_no

Format a bool as “yes” or “no”.

Example: assert_eq(fmt_yes_no(false), “no”);

pub fn fmt_yes_no(b: bool) -> str {

Parameters:

  • b: bool

Returns: str

Defined at line 181


fmt_pad_left

Pad a string to a minimum width with spaces on the left (right-aligned).

Example: assert_eq(fmt_pad_left(“ab”, 4), ” ab”);

pub fn fmt_pad_left(s: str, width: i64) -> str {

Parameters:

  • s: str
  • width: i64

Returns: str

Defined at line 194


fmt_pad_right

Pad a string to a minimum width, left-aligned (pad right with spaces).

Example: assert_eq(fmt_pad_right(“ab”, 4), “ab ”);

pub fn fmt_pad_right(s: str, width: i64) -> str {

Parameters:

  • s: str
  • width: i64

Returns: str

Defined at line 202


fmt_pad_center

Pad a string to a minimum width, centered.

Example: assert_eq(fmt_pad_center(“ab”, 6), ” ab ”);

pub fn fmt_pad_center(s: str, width: i64) -> str {

Parameters:

  • s: str
  • width: i64

Returns: str

Defined at line 210


fmt_commas

Format an i64 with thousands separators (commas). fmt_commas(1234567) → “1,234,567”

Example: assert_eq(fmt_commas(1234567), “1,234,567”); assert_eq(fmt_commas(-1000), “-1,000”); assert_eq(fmt_commas(999), “999”);

pub fn fmt_commas(n: i64) -> str {

Parameters:

  • n: i64

Returns: str

Defined at line 223


fmt_bytes

Format a byte count as a human-readable size. fmt_bytes(1536) → “1.5 KB” fmt_bytes(1048576) → “1.0 MB”

Example: assert_eq(fmt_bytes(1536), “1.5 KB”); assert_eq(fmt_bytes(1048576), “1.0 MB”); assert_eq(fmt_bytes(500), “500.0 B”);

pub fn fmt_bytes(bytes: i64) -> str {

Parameters:

  • bytes: i64

Returns: str

Defined at line 265


fmt_row

Format a Vec of strings as a row in a table (pipe-separated). fmt_row([“Name”, “Age”, “City”]) → ”| Name | Age | City |”

Example: var cols: Vec= Vec::new(); cols.push(“Name”); cols.push(“Age”); assert_eq(fmt_row(cols), ”| Name | Age |”);

pub fn fmt_row(cols: Vec<str>) -> str {

Parameters:

  • cols: Vec<str>

Returns: str

Defined at line 291


fmt_separator

Format a separator line for a table with N columns of given widths. Each column gets its width plus 2 dashes (the cell padding of fmt_row): fmt_separator([3, 1]) → ”+-----+---+”

Example: var w: Vec= Vec::new(); w.push(3); w.push(1); assert_eq(fmt_separator(w), ”+-----+---+”);

pub fn fmt_separator(widths: Vec<i64>) -> str {

Parameters:

  • widths: Vec<i64>

Returns: str

Defined at line 311


fmt_row_widths

Format a table row with specific column widths (cells right-aligned, padded on the left by fmt_pad_left).

Example: var cols: Vec= Vec::new(); cols.push(“a”); cols.push(“bb”); var w: Vec= Vec::new(); w.push(3); w.push(3); var row = fmt_row_widths(cols, w); println(row); assert_eq(row, ”| a | bb |”);

pub fn fmt_row_widths(cols: Vec<str>, widths: Vec<i64>) -> str {

Parameters:

  • cols: Vec<str>
  • widths: Vec<i64>

Returns: str

Defined at line 333


Generated by scribe, the Fides documentation generator