rok::core::fmt
rok::core::fmt - Formatter, Display / Debug, FormatSpec and the
f-string lowering targets (stdlib 2.10, refs-lang 1.7.3).
Every rendering writes into a Formatter: the runtime's growing text
plus the spec of the value being written. HIR lowers f"..." to one
such text: literal pieces and primitive holes go to the runtime
directly, any other hole through Display::fmt / Debug::fmt
(fstr_* below), and rok_fmt_finish hands the text over as the
str without a copy.
Structs
FmtError
pub struct FmtErrorA failed write (2.10.12). Writing to memory never fails.
Trait implementations 2
impl Display for FmtErrorimpl Debug for FmtError
FormatSpec
pub struct FormatSpecAn f-string spec, [[fill]align][sign][#][0][width][.precision][type]
(refs-lang 1.7.3). An absent ty is '\0'; the Display letters
s d g read as absent.
pub fill: charpub align: Alignment | nonepub sign: Sign | nonepub alt: boolpub zero: boolpub width: usize | nonepub precision: usize | nonepub ty: charpub const fn new() -> FormatSpecThe empty spec.
pub const fn parse(text: str) -> FormatSpectextparsed by the runtime with the parser the compiler checks static specs with; panics on a malformed spec.
Formatter
pub struct FormatterWhere a value's text goes, with the spec it is written by (2.10.2):
the runtime's growing text (rok_fmt_*) and the spec packed in two
words - flags: fill (bits 0..32), align, sign, type (a byte each
from bit 32), # (bit 56), 0 (bit 57); counts: width, precision
(32 bits each, all ones when absent).
pub const fn new() -> Formatterpub const fn with_capacity(cap: usize) -> FormatterEmpty, with room for
capbytes.pub const fn with_spec(spec: FormatSpec) -> FormatterEmpty, writing values per
spec.pub const fn finish(self) -> strThe text written, as a
str(no copy); the formatter is spent.pub const fn write_str(ref self, s: str) throws (FmtError)pub const fn write_char(ref self, c: char) throws (FmtError)pub const fn pad(ref self, s: str) throws (FmtError)scut toprecisionchars and padded towidth(text aligns left by default).pub const fn pad_integral(ref self, is_nonnegative: bool, prefix: str, buf: str) throws (FmtError)An integer: the sign,
prefix("0x"..) under#, the digitsbuf, padded towidth- right by default;0and=fill between the prefix and the digits.pub const fn fill(self) -> charpub const fn align(self) -> Alignment | nonenonewhen the spec names no alignment: numbers then align right, other values left.pub const fn sign(self) -> Sign | nonepub const fn alternate(self) -> boolpub const fn pad_zero(self) -> boolpub const fn width(self) -> usize | nonepub const fn precision(self) -> usize | none
Enums
Alignment
pub enum AlignmentThe spec's align.
LeftRightCenterEqual
Sign
pub enum SignThe spec's sign.
PlusMinusSpace
Traits
Display
pub trait DisplayWhat f"{x}" writes.
fn fmt(self, ref f: Formatter) throws (FmtError)
Debug
pub trait DebugWhat f"{x:?}" writes.
fn fmt(self, ref f: Formatter) throws (FmtError)
Functions
fstr_display
pub const fn fstr_display<T: Display>(t: str, v: T) -> str{v}.
fstr_debug
pub const fn fstr_debug<T: Debug>(t: str, v: T) -> str{v:?}.
fstr_num
pub fn fstr_num<T: Display>(t: str, v: T, flags: u64, counts: u64) -> strA number under a spec (flags, counts).
fstr_pack
pub const fn fstr_pack(spec: str, text_only: bool) -> (u64, u64)A dynamic spec's packed words; panics when malformed, or when
text_only and it has a number's type letter.
fstr_text_any
pub const fn fstr_text_any<T: Display + Debug>(t: str, v: T, spec: str) -> strA dynamic spec on a value with both: ? picks the Debug; then cut
and padded as text.