Browse the docs

silk.text.format.

Text output for values through the ambient Writer, compile-time checked templates, and decimal parsing.

When to use#

Use Format.display to write one value with default options. Use Format.displayWith to write one value with a width, fill, sign, or precision. Use Format.format to write a template such as "{name} has {count}" with values from a tuple or record. Implement Display to make your own type usable with all three. Implement Debug to show a value for a programmer with {:?}, Format.debug, and Format.debugWith.

Use Format.i32Value, Format.f64Value, and the other ...Value functions to read decimal text back into a number. They accept the default output of Display for the same type.

Details#

Output goes to the ambient Writer effect. A Formatter holds only the options. No operation in this module allocates, and none makes an intermediate String.

Integers display in decimal, or in hexadecimal, octal, or binary with a Style. Finite floats display as the shortest decimal that parses back to the same bits, and negative zero displays as -0. If you set a precision, a float displays with exactly that many fractional digits, rounded half to even. That output does not always parse back to the same bits.

Width counts Unicode scalars, not UTF-8 bytes and not terminal columns. The compiler parses and checks templates, selects fields, and selects Display implementations, so a bad template is a compile error, not a runtime error.

Errors#

  • WriterError if the ambient Writer fails. The bytes that the writer accepted before the failure stay written. This module does not roll output back.

  • ParseError from the ...Value parse functions, with the reason NotANumber or OutOfRange.

Numbers align to the right by default. Text, bool, and char align to the left by default.

Gotchas#

NaN and Infinity ignore precision and zero padding. To check that a float is finite before you display it, use f64.isFinite or f32.isFinite.

Examples#

Write a padded number and a template into a buffer#

silk
import silk.core.effect { Effect }
import silk.text.format { Alignment, Format, FormatOptions, Sign, Style }
import silk.core.option { Option }
import silk.io.writer { Writer, WriterError }

struct CaptureWriter {
  bytes: [u8; 64],
  length: usize,
}

impl Writer for CaptureWriter {
  effect fn writeAll(self: &mut Self, value: &[u8]) -> ()
    ! WriterError
    ? &mut Writer {
    let mut index: usize = 0
    while index < value.length {
      self.bytes[self.length] = value[index]
      self.length = self.length + 1
      index = index + 1
    }
    return ()
  }

  effect fn flush(self: &mut Self) -> ()
    ! WriterError
    ? &mut Writer {
    return ()
  }
}

fn holds(writer: &CaptureWriter, expected: &[u8]) -> bool {
  if writer.length != expected.length {
    return false
  }
  let mut index: usize = 0
  while index < expected.length {
    if writer.bytes[index] != expected[index] {
      return false
    }
    index = index + 1
  }
  return true
}

effect fn render() -> ()
  ! WriterError
  ? &mut Writer {
  let value = 42
  let options = FormatOptions {
    width: Option<usize>.some(6),
    alignment: Alignment.Right,
    fill: '.',
    sign: Sign.Always,
    alternate: false,
    zeroPad: false,
    precision: Option<usize>.none(),
    color: false,
    style: Style.Default,
  }
  run Format.displayWith(&value, move options)
  let args = .{ name: "Ada", count: 3 }
  return run Format.format(" {name} has {count}", &args)
}

pub effect fn main() -> i32
  ! WriterError {
  let mut writer = CaptureWriter { bytes: [0; 64], length: 0 }
  run render() |> Effect.provideMut<Writer>(&mut writer)
  if !holds(&writer, b"...+42 Ada has 3") {
    return 1
  }
  return 0
}

Read a number from text#

silk
import silk.text.format { Format, NotANumber, OutOfRange, ParseError }
import silk.core.result { Result }

fn read(text: string) -> i32 {
  return match move Format.i32Value(text) {
    Result<i32, ParseError>.Success { value } => value
    Result<i32, ParseError>.Failure { error } => match move error.reason {
      NotANumber { offset } => -1
      OutOfRange {} => -2
    }
  }
}

pub fn main() -> i32 {
  if read("-17") != -17 || read("12x") != -1 || read("3000000000") != -2 {
    return 1
  }
  return 0
}

See also#

  • silk.io.writer for the Writer effect that receives the output.

  • silk.io.writer_native for StdoutWriter and StderrWriter, which write to standard output and standard error.

Import as Format with import silk.text.format { Format }.

Public declarations: 14.

Format#

silk
pub struct Format

The owner type of the formatting and parsing operations. It has no fields and is never constructed.

When to use#

Use Format.display to write one value with default options, Format.displayWith to set a width, fill, sign, or precision, and Format.format to write a template such as "{name} has {count}". Use Format.debug to show a value for a programmer. Use Format.i32Value, Format.f64Value, and the other ...Value functions to read decimal text back into a number. They accept the default Display output of the same type.

Details#

Output goes to the ambient Writer effect. No operation allocates, and none makes an intermediate String. Integers display in decimal, or in another base with a Style. Finite floats display as the shortest decimal that parses back to the same bits, and negative zero displays as -0. With a precision, a float displays with exactly that many fractional digits, rounded half to even, and that output does not always parse back to the same bits. Width counts Unicode scalars, not UTF-8 bytes and not terminal columns. Numbers align to the right by default. Text, bool, and char align to the left by default.

Errors#

  • WriterError if the ambient Writer fails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.

  • ParseError from the ...Value parse functions.

Gotchas#

NaN and Infinity ignore precision and zero padding. To check that a float is finite before you display it, use f64.isFinite or f32.isFinite.

Implementation Format#

silk
impl Format

Associated function defaultOptions#

silk
pub fn defaultOptions() -> FormatOptions

Returns the default FormatOptions.

Details#

The defaults are: no width, Alignment.Default, a space as fill, Sign.NegativeOnly, no alternate form, no zero padding, no precision, no color, and Style.Default. Format.display uses these options.

Associated function make#

silk
pub fn make(options: FormatOptions) -> Formatter

Returns a Formatter that uses options.

When to use#

Use make when you call Display.display directly. Format.displayWith calls it for you.

Associated function makeDefault#

silk
pub fn makeDefault() -> Formatter

Returns a Formatter that uses Format.defaultOptions.

Method hasWidth#

silk
pub fn hasWidth(self: &Formatter) -> bool

Returns true if the options set a minimum width.

Method width#

silk
pub fn width(self: &Formatter) -> usize

Returns the minimum width in Unicode scalars. Returns 0 if the options set no width.

Method alignment#

silk
pub fn alignment(self: &Formatter) -> Alignment

Returns the alignment of the content inside the width.

Method fill#

silk
pub fn fill(self: &Formatter) -> char

Returns the character that fills the space up to the width.

Method sign#

silk
pub fn sign(self: &Formatter) -> Sign

Returns the sign rule for numbers.

Method style#

silk
pub fn style(self: &Formatter) -> Style

Returns the style that selects the number base or notation.

Method alternate#

silk
pub fn alternate(self: &Formatter) -> bool

Returns true if the options ask for the alternate form.

Details#

The standard integers write a base prefix (0x, 0o, 0b) in the alternate form of a Style other than Style.Default. A Display implementation that you write can use the flag and must document what it changes.

Method zeroPad#

silk
pub fn zeroPad(self: &Formatter) -> bool

Returns true if the options ask to pad numbers with zeros up to the width.

Details#

The zeros go after the sign, so -7 with width 4 displays as -007. A precision turns off this padding for integers but not for floats. NaN and Infinity pad with the fill character.

Method hasPrecision#

silk
pub fn hasPrecision(self: &Formatter) -> bool

Returns true if the options set a precision.

Method precision#

silk
pub fn precision(self: &Formatter) -> usize

Returns the precision. Returns 0 if the options set no precision.

Details#

For integers, the precision is the minimum number of digits, with leading zeros. For floats, it is the exact number of digits after the decimal point. For text, it is the maximum number of Unicode scalars.

Method color#

silk
pub fn color(self: &Formatter) -> bool

Returns true if the output can contain ANSI color codes.

Details#

This is a permission, not a request. The standard Display implementations never write color codes.

Method write#

silk
pub effect fn write(
    self: &mut Formatter,
    bytes: &[u8]
  ) -> () ! WriterError ? &mut Writer

Writes bytes to the ambient Writer as they are. It does not apply width or other options.

Errors#

  • WriterError if the ambient Writer fails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.

Method writeText#

silk
pub effect fn writeText(
    self: &mut Formatter,
    text: string
  ) -> () ! WriterError ? &mut Writer

Writes the UTF-8 bytes of text to the ambient Writer. It does not apply width or other options.

Errors#

  • WriterError if the ambient Writer fails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.

Method writePadding#

silk
pub effect fn writePadding(
    self: &mut Formatter,
    count: usize
  ) -> () ! WriterError ? &mut Writer

Writes the fill character count times.

Errors#

  • WriterError if the ambient Writer fails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.

Method leadingPadding#

silk
pub fn leadingPadding(self: &Formatter, contentWidth: usize) -> usize

Returns how many fill characters go before content that is contentWidth scalars wide.

When to use#

Use it in a Display implementation to align content whose byte length is not its visible width, for example content with ANSI color codes. Pair it with Format.trailingPadding, or use Format.writeLeadingPadding to write the fill.

Details#

The result is 0 if the width is not more than contentWidth. Otherwise the extra space is the width minus contentWidth. Alignment.Default and Alignment.Right put all of it before the content. Alignment.Left puts none of it there. Alignment.Center puts half of it there, rounded down.

Method trailingPadding#

silk
pub fn trailingPadding(self: &Formatter, contentWidth: usize) -> usize

Returns how many fill characters go after content that is contentWidth scalars wide.

Details#

The result is 0 if the width is not more than contentWidth. Alignment.Left puts all extra space after the content. Alignment.Default and Alignment.Right put none of it there. Alignment.Center puts half of it there, rounded up, so the two sides add up to the extra space.

Method writeLeadingPadding#

silk
pub effect fn writeLeadingPadding(
    self: &mut Formatter,
    contentWidth: usize
  ) -> () ! WriterError ? &mut Writer

Writes the fill that goes before content that is contentWidth scalars wide. The count comes from Format.leadingPadding.

Errors#

  • WriterError if the ambient Writer fails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.

Method writeTrailingPadding#

silk
pub effect fn writeTrailingPadding(
    self: &mut Formatter,
    contentWidth: usize
  ) -> () ! WriterError ? &mut Writer

Writes the fill that goes after content that is contentWidth scalars wide. The count comes from Format.trailingPadding.

Errors#

  • WriterError if the ambient Writer fails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.

Method padText#

silk
pub effect fn padText(
    self: &mut Formatter,
    text: string
  ) -> () ! WriterError ? &mut Writer

Writes text with the width, fill, alignment, and precision of the options.

When to use#

Use it in a Display implementation that writes one piece of text, so that your type pads and cuts like a string does. The Display implementation for string calls it.

Details#

The precision is the maximum number of Unicode scalars to write, and the rest is cut. The width counts the scalars that are written. Alignment.Default puts the content on the left. The sign, zero padding, and alternate options do not apply.

Errors#

  • WriterError if the ambient Writer fails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.

Method padNumber#

silk
pub effect fn padNumber(
    self: &mut Formatter,
    negative: bool,
    prefix: string,
    digits: string
  ) -> () ! WriterError ? &mut Writer

Writes the digits of a number with the sign, width, fill, alignment, and zero padding of the options.

When to use#

Use it in a Display implementation for a number type, so that your type pads like the standard integers. Calculate the digits yourself, without a sign.

Details#

The output is the sign, then prefix, then digits. The sign comes from negative and the sign rule. prefix is text such as 0x that goes before the digits; use "" for none. Zero padding puts the zeros between prefix and digits. Alignment.Default puts the content on the right. This operation ignores the precision.

Errors#

  • WriterError if the ambient Writer fails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.

Associated function display#

silk
pub effect fn display<T: Display>(value: &T) -> () ! WriterError ? &mut Writer

Writes value to the ambient Writer with Format.defaultOptions.

When to use#

Use display to write one value. Use Format.displayWith to set a width, fill, sign, or precision. Use Format.format to write several values in a template.

Errors#

  • WriterError if the ambient Writer fails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.

Associated function displayWith#

silk
pub effect fn displayWith<T: Display>(
    value: &T,
    options: FormatOptions
  ) -> () ! WriterError ? &mut Writer

Writes value to the ambient Writer with options.

Details#

For integers, the precision is a minimum digit count and turns off zero padding. For floats, the precision is the exact number of fractional digits, rounded half to even. For text, the precision is the maximum number of Unicode scalars, and the rest is cut. Integers use style for the base and alternate for the base prefix. The standard implementations ignore color. Width counts Unicode scalars. Numbers align to the right by default. Text, bool, and char align to the left by default.

Gotchas#

NaN and Infinity ignore precision and zero padding. With a precision, float output does not always parse back to the same bits.

Errors#

  • WriterError if the ambient Writer fails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.

Associated function debug#

silk
pub effect fn debug<T: Debug>(value: &T) -> () ! WriterError ? &mut Writer

Writes the Debug form of value to the ambient Writer with Format.defaultOptions.

When to use#

Use it to show a value to a programmer, for example in a log or a test failure. Strings show with quotes and escapes, so you can see spaces and control characters.

Errors#

  • WriterError if the ambient Writer fails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.

Associated function debugWith#

silk
pub effect fn debugWith<T: Debug>(
    value: &T,
    options: FormatOptions
  ) -> () ! WriterError ? &mut Writer

Writes the Debug form of value to the ambient Writer with options.

Details#

alternate selects the pretty form, with one field or element on each line and four spaces of indentation for each level. Numbers apply the other options as Display does.

Errors#

  • WriterError if the ambient Writer fails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.

Associated function debugFields#

silk
pub effect fn debugFields<T>(
    value: &T,
    static name: string<'static>,
    formatter: &mut Formatter
  ) -> () ! WriterError ? &mut Writer

Writes the visible fields of value in the Debug form, after name.

When to use#

Use it to implement Debug for your struct in one line: return run Format.debugFields(self, "Point", &mut formatter).

Details#

A struct with labeled fields writes Point { x: 1, y: 2 }. A struct with positional fields writes Pair(1, 2). With no visible field, only name is written. The pretty form (Format.alternate) puts each field on its own line. Every field must implement Debug; the compiler checks this for each type that you call it with.

Errors#

  • WriterError if the ambient Writer fails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.

Gotchas#

Reflection sees fields from this module, so it shows only the pub fields of your type. To show private fields, write the Debug implementation by hand.

Associated function debugList#

silk
pub effect fn debugList<T: Debug>(
    values: &[T],
    formatter: &mut Formatter
  ) -> () ! WriterError ? &mut Writer

Writes the elements of values in the Debug form, as [1, 2, 3].

When to use#

Use it to implement Debug for a type that holds a sequence. The pretty form (Format.alternate) puts each element on its own line.

Errors#

  • WriterError if the ambient Writer fails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.

Associated function debugRecord#

silk
pub effect fn debugRecord(
    name: string,
    formatter: &mut Formatter
  ) -> DebugRecord ! WriterError ? &mut Writer

Starts the Debug form of a value with labeled fields by writing name.

When to use#

Use it to implement Debug by hand when Format.debugFields does not fit: the type has private fields, or it is a union with fields in a variant. Write each field with Format.debugField and end with Format.debugFinish. This one leaves out a secret:

silk
import silk.text.format { Debug, Format, Formatter }
import silk.io.writer { Writer, WriterError }

struct Account {
  pub name: string,
  secret: string,
}

impl Debug for Account {
  effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer {
    let mut record = run Format.debugRecord("Account", &mut formatter)
    run Format.debugField(&mut record, "name", &self.name, &mut formatter)
    return run Format.debugFinish(record, &mut formatter)
  }
}

pub fn main() -> i32 {
  let account = Account { name: "ada", secret: "hunter2" }
  return 0
}

It writes Account { name: "ada" }. A record with no field writes only its name. The pretty form (Format.alternate) puts each field on its own line.

Errors#

  • WriterError if the ambient Writer fails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.

Associated function debugField#

silk
pub effect fn debugField<T: Debug>(
    record: &mut DebugRecord,
    label: string,
    value: &T,
    formatter: &mut Formatter
  ) -> () ! WriterError ? &mut Writer

Writes one field of a record that Format.debugRecord started, as label: value.

Errors#

  • WriterError if the ambient Writer fails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.

Associated function debugFinish#

silk
pub effect fn debugFinish(
    record: DebugRecord,
    formatter: &mut Formatter
  ) -> () ! WriterError ? &mut Writer

Ends a record that Format.debugRecord started. It writes the closing } when the record has a field.

Errors#

  • WriterError if the ambient Writer fails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.

Associated function format#

silk
pub effect fn format<Args>(
    static template: string<'static>,
    args: &Args
  ) -> () ! WriterError ? &mut Writer

Writes template to the ambient Writer and replaces each placeholder with a value from args.

When to use#

Use format when the text is known at compile time and each value implements Display.

Details#

  • {} takes the next field of a tuple, in order.

  • {1} takes the tuple field 1. The same field can show more than one time. {} counts from field 0 and ignores the {1} placeholders, as in Rust.

  • {name} takes the record field name.

  • {{ writes { and }} writes }.

A placeholder can set options after a colon, as in Rust: {:>8}, {name:*^10.2}. The options are, in this order and each optional:

  • A fill character and an alignment: < left, ^ center, > right. The fill needs an alignment after it, so {:*<6} pads with *. Without a fill, the fill is a space.

  • + for Sign.Always. - is the default and changes nothing.

  • # for the alternate form.

  • 0 for zero padding.

  • A width in decimal digits, or 1$ or w$ to take it from the integer field 1 or w.

  • . and a precision in decimal digits, or .1$ or .p$ to take it from an integer field. For an integer value the precision is a minimum count of digits, so {:.3} of 7 is 007; Rust ignores it there.

  • A type: x lowercase hexadecimal, X uppercase hexadecimal, o octal, b binary. These need an integer, and # adds the prefix 0x, 0o, or 0b. e and E write a float in scientific notation, such as 1.25e3; these need a float. ? writes the Debug form, and #? the pretty Debug form.

The compiler parses the options and checks the template and the fields. A placeholder without options uses Format.defaultOptions. format borrows args.

Errors#

  • WriterError if the ambient Writer fails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.

Gotchas#

One template cannot mix tuple fields and record fields: {}, {1}, and 1$ need a tuple, and {name} and w$ need a record. A template with tuple fields must use each field at least one time, as a value, a width, or a precision. A malformed template, a malformed option, a field that does not exist, or a type such as x on a value that it does not apply to is a compile error. A width or precision field that is not an integer is a compile error, and a negative one traps. Sign.Space and color are available only through FormatOptions.

Examples#

Write a tuple and a record#

silk
import silk.core.effect { Effect }
import silk.text.format { Format }
import silk.io.writer { Writer, WriterError }

struct CaptureWriter {
  bytes: [u8; 64],
  length: usize,
}

impl Writer for CaptureWriter {
  effect fn writeAll(self: &mut Self, value: &[u8]) -> ()
    ! WriterError
    ? &mut Writer {
    let mut index: usize = 0
    while index < value.length {
      self.bytes[self.length] = value[index]
      self.length = self.length + 1
      index = index + 1
    }
    return ()
  }

  effect fn flush(self: &mut Self) -> ()
    ! WriterError
    ? &mut Writer {
    return ()
  }
}

fn holds(writer: &CaptureWriter, expected: &[u8]) -> bool {
  if writer.length != expected.length {
    return false
  }
  let mut index: usize = 0
  while index < expected.length {
    if writer.bytes[index] != expected[index] {
      return false
    }
    index = index + 1
  }
  return true
}

effect fn render() -> ()
  ! WriterError
  ? &mut Writer {
  let pair = (3, 4)
  run Format.format("{} + {} = 7. ", &pair)
  let user = .{ name: "Ada", age: 36 }
  run Format.format("{name} is {age} {{years}}. ", &user)
  let price = .{ item: "tea", cost: 2.5 }
  run Format.format("[{item:.<6}{cost:>6.2}] ", &price)
  return run Format.format("{:#06x} {:b} {:.2e}", &(255, 5, 1234.5))
}

effect fn reuse() -> ()
  ! WriterError
  ? &mut Writer {
  let width: usize = 5
  run Format.format("{0}-{1}-{0} ", &("ab", 7))
  return run Format.format("[{name:>width$}]", &.{ name: "Ada", width: width })
}

pub effect fn main() -> i32
  ! WriterError {
  let mut writer = CaptureWriter { bytes: [0; 64], length: 0 }
  run render() |> Effect.provideMut<Writer>(&mut writer)
  if !holds(&writer, b"3 + 4 = 7. Ada is 36 {years}. [tea...  2.50] 0x00ff 101 1.23e3") {
    return 1
  }
  let mut second = CaptureWriter { bytes: [0; 64], length: 0 }
  run reuse() |> Effect.provideMut<Writer>(&mut second)
  if !holds(&second, b"ab-7-ab [  Ada]") {
    return 1
  }
  return 0
}

Associated function unsignedValue#

silk
pub fn unsignedValue(text: string) -> Result<u64, ParseError>

Reads all of text as a decimal u64.

Details#

text must contain only the digits 0 to 9. Signs, spaces, and separators are not accepted. Leading zeros are accepted.

Errors#

  • NotANumber if text is empty or has a character that is not part of the number. The offset is the position of that character, or the length of text if a digit is missing at the end.

  • OutOfRange if the value is more than u64.MAX.

Associated function signedValue#

silk
pub fn signedValue(text: string) -> Result<i64, ParseError>

Reads all of text as a decimal i64. One leading - is accepted.

Details#

i64.MIN reads correctly. A leading +, spaces, and separators are not accepted.

Errors#

  • NotANumber if text is empty or has a character that is not part of the number. The offset is the position of that character, or the length of text if a digit is missing at the end.

  • OutOfRange if the value is less than i64.MIN or more than i64.MAX.

Associated function f64Value#

silk
pub fn f64Value(text: string) -> Result<f64, ParseError>

Reads all of text as a decimal f64.

Details#

The accepted form is an optional + or -, digits with an optional . and fraction, and an optional exponent e or E with an optional sign. There must be at least one digit before or after the .. The value is rounded correctly to the nearest f64, with ties to even. A value too large for f64 becomes infinity with the same sign. A value too small becomes zero with the same sign. The result does not depend on floating-point arithmetic of the target.

Errors#

  • NotANumber if text is empty or has a character that is not part of the number. The offset is the position of that character, or the length of text if a digit is missing at the end.

Gotchas#

NaN, Infinity, and inf are not accepted, so the output of Display for a value that is not finite does not parse back.

Associated function f32Value#

silk
pub fn f32Value(text: string) -> Result<f32, ParseError>

Reads all of text as a decimal f32.

Details#

The accepted form is an optional + or -, digits with an optional . and fraction, and an optional exponent e or E with an optional sign. There must be at least one digit before or after the .. The value is rounded correctly to the nearest f32, with ties to even. A value too large for f32 becomes infinity with the same sign. A value too small becomes zero with the same sign. The text is rounded to f32 directly, not through f64, so there is no double rounding.

Errors#

  • NotANumber if text is empty or has a character that is not part of the number. The offset is the position of that character, or the length of text if a digit is missing at the end.

Gotchas#

NaN, Infinity, and inf are not accepted, so the output of Display for a value that is not finite does not parse back.

Associated function u8Value#

silk
pub fn u8Value(text: string) -> Result<u8, ParseError>

Reads all of text as a decimal u8.

Details#

text must contain only the digits 0 to 9. Signs, spaces, and separators are not accepted. Leading zeros are accepted.

Errors#

  • NotANumber if text is empty or has a character that is not part of the number. The offset is the position of that character, or the length of text if a digit is missing at the end.

  • OutOfRange if the value is more than u8.MAX.

Associated function u16Value#

silk
pub fn u16Value(text: string) -> Result<u16, ParseError>

Reads all of text as a decimal u16.

Details#

text must contain only the digits 0 to 9. Signs, spaces, and separators are not accepted. Leading zeros are accepted.

Errors#

  • NotANumber if text is empty or has a character that is not part of the number. The offset is the position of that character, or the length of text if a digit is missing at the end.

  • OutOfRange if the value is more than u16.MAX.

Associated function u32Value#

silk
pub fn u32Value(text: string) -> Result<u32, ParseError>

Reads all of text as a decimal u32.

Details#

text must contain only the digits 0 to 9. Signs, spaces, and separators are not accepted. Leading zeros are accepted.

Errors#

  • NotANumber if text is empty or has a character that is not part of the number. The offset is the position of that character, or the length of text if a digit is missing at the end.

  • OutOfRange if the value is more than u32.MAX.

Associated function u64Value#

silk
pub fn u64Value(text: string) -> Result<u64, ParseError>

Reads all of text as a decimal u64.

Details#

text must contain only the digits 0 to 9. Signs, spaces, and separators are not accepted. Leading zeros are accepted.

Errors#

  • NotANumber if text is empty or has a character that is not part of the number. The offset is the position of that character, or the length of text if a digit is missing at the end.

  • OutOfRange if the value is more than u64.MAX.

Associated function usizeValue#

silk
pub fn usizeValue(text: string) -> Result<usize, ParseError>

Reads all of text as a decimal usize.

Details#

text must contain only the digits 0 to 9. Signs, spaces, and separators are not accepted. Leading zeros are accepted.

Errors#

  • NotANumber if text is empty or has a character that is not part of the number. The offset is the position of that character, or the length of text if a digit is missing at the end.

  • OutOfRange if the value is more than usize.MAX.

Associated function i8Value#

silk
pub fn i8Value(text: string) -> Result<i8, ParseError>

Reads all of text as a decimal i8. One leading - is accepted.

Details#

Only the digits 0 to 9 and one leading - are accepted. The minimum value reads correctly. A leading +, spaces, and separators are not accepted.

Errors#

  • NotANumber if text is empty or has a character that is not part of the number. The offset is the position of that character, or the length of text if a digit is missing at the end.

  • OutOfRange if the value is less than i8.MIN or more than i8.MAX.

Associated function i16Value#

silk
pub fn i16Value(text: string) -> Result<i16, ParseError>

Reads all of text as a decimal i16. One leading - is accepted.

Details#

Only the digits 0 to 9 and one leading - are accepted. The minimum value reads correctly. A leading +, spaces, and separators are not accepted.

Errors#

  • NotANumber if text is empty or has a character that is not part of the number. The offset is the position of that character, or the length of text if a digit is missing at the end.

  • OutOfRange if the value is less than i16.MIN or more than i16.MAX.

Associated function i32Value#

silk
pub fn i32Value(text: string) -> Result<i32, ParseError>

Reads all of text as a decimal i32. One leading - is accepted.

Details#

Only the digits 0 to 9 and one leading - are accepted. The minimum value reads correctly. A leading +, spaces, and separators are not accepted.

Errors#

  • NotANumber if text is empty or has a character that is not part of the number. The offset is the position of that character, or the length of text if a digit is missing at the end.

  • OutOfRange if the value is less than i32.MIN or more than i32.MAX.

Associated function i64Value#

silk
pub fn i64Value(text: string) -> Result<i64, ParseError>

Reads all of text as a decimal i64. One leading - is accepted.

Details#

Only the digits 0 to 9 and one leading - are accepted. The minimum value reads correctly. A leading +, spaces, and separators are not accepted.

Errors#

  • NotANumber if text is empty or has a character that is not part of the number. The offset is the position of that character, or the length of text if a digit is missing at the end.

  • OutOfRange if the value is less than i64.MIN or more than i64.MAX.

Associated function isizeValue#

silk
pub fn isizeValue(text: string) -> Result<isize, ParseError>

Reads all of text as a decimal isize. One leading - is accepted.

Details#

Only the digits 0 to 9 and one leading - are accepted. The minimum value reads correctly. A leading +, spaces, and separators are not accepted.

Errors#

  • NotANumber if text is empty or has a character that is not part of the number. The offset is the position of that character, or the length of text if a digit is missing at the end.

  • OutOfRange if the value is less than isize.MIN or more than isize.MAX.

Alignment#

silk
pub enum Alignment

Where content goes inside a width that is larger than the content.

Details#

For the standard Display implementations, Default is Right for numbers and Left for text, bool, and char.

Default#

silk
Default

Uses the default of the Display implementation. The standard implementations align numbers to the right and text to the left.

Left#

silk
Left

Puts the content first and all fill after it.

Center#

silk
Center

Puts half of the fill before the content and half after it. An odd extra fill character goes after it.

silk
Right

Puts all fill before the content.

Sign#

silk
pub enum Sign

How numbers that are not negative show a sign.

NegativeOnly#

silk
NegativeOnly

Writes - for negative numbers and no sign for other numbers.

Always#

silk
Always

Writes - for negative numbers and + for other numbers, including zero.

Space#

silk
Space

Writes - for negative numbers and one space for other numbers, so columns of numbers align.

Style#

silk
pub enum Style

The base or notation that a number displays in.

Details#

The standard integers use the base styles: LowerHex, UpperHex, Octal, and Binary. With the alternate form, they write the prefix 0x, 0o, or 0b before the digits. The standard floats use LowerExp and UpperExp. Each standard type ignores the other styles.

Gotchas#

A negative integer in a base other than decimal displays as its two's complement bits at the width of its type, with no sign, as in Rust: -1 as i8 in LowerHex is ff.

Default#

silk
Default

Decimal for integers, and the normal form of other types.

LowerHex#

silk
LowerHex

Base 16 with the digits 0 to 9 and a to f.

UpperHex#

silk
UpperHex

Base 16 with the digits 0 to 9 and A to F.

Octal#

silk
Octal

Base 8.

Binary#

silk
Binary

Base 2.

LowerExp#

silk
LowerExp

Scientific notation with a lowercase e, such as 1.25e3. The significand has one digit before the point. Without a precision, its digits are the shortest that parse back to the same bits. With a precision, it has that many fractional digits, rounded half to even.

UpperExp#

silk
UpperExp

Scientific notation with an uppercase E, such as 1.25E3.

FormatOptions#

silk
pub struct FormatOptions

The options that control how a value displays.

Details#

Format.defaultOptions returns the defaults. To change some options, start from the defaults and set the fields you need. The standard Display implementations ignore color.

Field width#

silk
pub width: Option<usize>

The minimum width in Unicode scalars, not UTF-8 bytes or terminal columns. Content that is wider is not cut.

Field alignment#

silk
pub alignment: Alignment

Where the content goes inside the width.

Field fill#

silk
pub fill: char

The character that fills the space up to the width.

Field sign#

silk
pub sign: Sign

How numbers that are not negative show a sign.

Field alternate#

silk
pub alternate: bool

Permission for a Display implementation to use its alternate form. The standard integers use it to write a base prefix such as 0x.

Field zeroPad#

silk
pub zeroPad: bool

If true, numbers pad to the width with zeros after the sign instead of the fill. A precision turns this off for integers but not for floats.

Field precision#

silk
pub precision: Option<usize>

The number of digits for numbers.

Details#

For integers, it is the minimum number of digits, with leading zeros. For floats, it is the exact number of fractional digits, rounded half to even. The result then does not always parse back to the same bits. NaN and Infinity ignore it. For text, it is the maximum number of Unicode scalars to write.

Field color#

silk
pub color: bool

Permission, not a request, to write ANSI color codes. The standard implementations never write them.

Field style#

silk
pub style: Style

The base or notation for numbers.

Formatter#

silk
pub struct Formatter

The options for one Display call.

Details#

A Formatter holds options only. The output goes to the ambient Writer, not to the formatter. Width counts Unicode scalars, not UTF-8 bytes and not terminal columns. Read the options with Format.width, Format.sign, and the other accessors.

DebugRecord#

silk
pub struct DebugRecord

A record that a hand-written Debug implementation is writing. Start one with Format.debugRecord.

Implementation Copy for DebugRecord#

silk
impl Copy for DebugRecord

Display#

silk
pub interface Display

A type that can write itself as text for people to read.

When to use#

Implement Display for your type to use it with Format.display, Format.displayWith, and Format.format.

Details#

The implementation reads the options from the Formatter and writes through the ambient Writer. It must not allocate. To apply the width, compute the visible width of your output and use Format.writeLeadingPadding and Format.writeTrailingPadding.

Examples#

Display a point as (x, y)#

silk
import silk.core.effect { Effect }
import silk.text.format { Display, Format, Formatter }
import silk.io.writer { Writer, WriterError }

struct CaptureWriter {
  bytes: [u8; 64],
  length: usize,
}

impl Writer for CaptureWriter {
  effect fn writeAll(self: &mut Self, value: &[u8]) -> ()
    ! WriterError
    ? &mut Writer {
    let mut index: usize = 0
    while index < value.length {
      self.bytes[self.length] = value[index]
      self.length = self.length + 1
      index = index + 1
    }
    return ()
  }

  effect fn flush(self: &mut Self) -> ()
    ! WriterError
    ? &mut Writer {
    return ()
  }
}

fn holds(writer: &CaptureWriter, expected: &[u8]) -> bool {
  if writer.length != expected.length {
    return false
  }
  let mut index: usize = 0
  while index < expected.length {
    if writer.bytes[index] != expected[index] {
      return false
    }
    index = index + 1
  }
  return true
}

struct Point {
  x: i32,
  y: i32,
}

effect fn showPoint(self: &Point, formatter: &mut Formatter) -> ()
  ! WriterError
  ? &mut Writer {
  run Format.writeText(&mut formatter, "(")
  run Format.display(&self.x)
  run Format.writeText(&mut formatter, ", ")
  run Format.display(&self.y)
  return run Format.writeText(&mut formatter, ")")
}

impl Display for Point {
  display: Point.showPoint
}

pub effect fn main() -> i32
  ! WriterError {
  let mut writer = CaptureWriter { bytes: [0; 64], length: 0 }
  let point = Point { x: 3, y: -4 }
  run Format.display(&point) |> Effect.provideMut<Writer>(&mut writer)
  if !holds(&writer, b"(3, -4)") {
    return 1
  }
  return 0
}

Operation display#

silk
effect fn display(
    self: &Self,
    formatter: &mut Formatter
  ) -> () ! WriterError ? &mut Writer

Writes self to the ambient Writer with the options in formatter.

Errors#

  • WriterError if the ambient Writer fails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.

RadixDisplay#

silk
pub interface RadixDisplay

An integer type that can display in a base other than decimal.

When to use#

Implement it for your own integer type to use it with the x, X, o, and b types in Format.format. The standard integers implement it.

Details#

Format.format calls displayRadix for a placeholder with a base type, so a base type on a value that is not an integer is a compile error. The options carry the base in FormatOptions.style. A style that is not a base, such as Style.LowerExp, is decimal.

Operation displayRadix#

silk
effect fn displayRadix(
    self: &Self,
    formatter: &mut Formatter
  ) -> () ! WriterError ? &mut Writer

Writes the value in the base that Format.style selects. A style that is not a base is decimal.

ExponentDisplay#

silk
pub interface ExponentDisplay

A float type that can display in scientific notation.

When to use#

Implement it for your own float type to use it with the e and E types in Format.format. f32 and f64 implement it.

Details#

Format.format calls displayExponent for a placeholder with e or E, so these types on a value that is not a float are a compile error.

Operation displayExponent#

silk
effect fn displayExponent(
    self: &Self,
    formatter: &mut Formatter
  ) -> () ! WriterError ? &mut Writer

Writes the value in the notation that Format.style selects. A style that is not Style.LowerExp or Style.UpperExp writes the normal form.

Debug#

silk
pub interface Debug

A type that can write itself for a programmer to read, as {:?} in Format.format.

When to use#

Implement Debug to show a value in logs, test failures, and assertions. Unlike Display, the output shows the structure of the value: strings are quoted and escaped, and a struct shows its fields. For a struct, call Format.debugFields; for a sequence, call Format.debugList.

Details#

The standard integers and bool write the same text as Display. Floats also do, but a whole number ends in .0, as 1.0. string and char write quotes and escapes. Option and Result write the variant and its value, such as Some(3). List and slices write their elements, as [1, 2, 3]. Format.alternate selects the pretty form, which puts each field on its own line. Nested values share the formatter, so the pretty form indents at each level.

A fixed array and an anonymous tuple or record cannot implement Debug. They still have a Debug form wherever the type is known as a field: as a {:?} argument of Format.format and as a field that Format.debugFields writes. An array writes [1, 2], an anonymous tuple (1, "a"), and an anonymous record { x: 1 }.

Gotchas#

Format.debug and a T: Debug bound still need a Debug implementation, so an array or an anonymous tuple cannot be passed to Format.debug or held in an Option or a List that writes its Debug form. Pass it as a {:?} argument instead, as Format.format("{:?}", &(values, )), or write a slice of an array with &values.

Operation debug#

silk
effect fn debug(
    self: &Self,
    formatter: &mut Formatter
  ) -> () ! WriterError ? &mut Writer

Writes the Debug form of the value through the ambient mutable Writer.

Errors#

  • WriterError if the ambient Writer fails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.

NotANumber#

silk
pub struct NotANumber

The reason for a ParseError when the text is not a number of the expected form.

Field offset#

silk
pub offset: usize

The byte offset of the first character that is not accepted. It is the length of the text if a digit is missing at the end.

Implementation Debug for NotANumber#

silk
impl Debug for NotANumber

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the fields, as NotANumber { offset: ... }.

OutOfRange#

silk
pub struct OutOfRange

The reason for a ParseError when the text is a number but the value does not fit the target type.

Implementation Debug for OutOfRange#

silk
impl Debug for OutOfRange

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes OutOfRange.

ParseError#

silk
pub struct ParseError

The error from the ...Value parse functions.

Details#

Use match on reason to get NotANumber or OutOfRange.

Field reason#

silk
pub reason: NotANumber | OutOfRange

Why the text was not accepted.

Implementation Debug for ParseError#

silk
impl Debug for ParseError

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the reason, as ParseError { reason: NotANumber { offset: 2 } }.

Implementation Display for u8#

silk
impl Display for u8

Operation display#

silk
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the value in the base of Format.style, decimal by default. Sign, precision, zero padding, width, fill, and alignment apply.

Details#

The order is: leading fill, sign, base prefix, zeros from the precision or from zeroPad, digits, trailing fill. Only the alternate form writes a base prefix. A base other than decimal writes no sign: a negative value displays as its two's complement bits at the width of its type, as -1 as i8 in LowerHex is ff.

Implementation RadixDisplay for u8#

silk
impl RadixDisplay for u8

Operation displayRadix#

silk
effect fn displayRadix(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Implementation Display for u16#

silk
impl Display for u16

Operation display#

silk
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the value in the base of Format.style, decimal by default. Sign, precision, zero padding, width, fill, and alignment apply.

Details#

The order is: leading fill, sign, base prefix, zeros from the precision or from zeroPad, digits, trailing fill. Only the alternate form writes a base prefix. A base other than decimal writes no sign: a negative value displays as its two's complement bits at the width of its type, as -1 as i8 in LowerHex is ff.

Implementation RadixDisplay for u16#

silk
impl RadixDisplay for u16

Operation displayRadix#

silk
effect fn displayRadix(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Implementation Display for u32#

silk
impl Display for u32

Operation display#

silk
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the value in the base of Format.style, decimal by default. Sign, precision, zero padding, width, fill, and alignment apply.

Details#

The order is: leading fill, sign, base prefix, zeros from the precision or from zeroPad, digits, trailing fill. Only the alternate form writes a base prefix. A base other than decimal writes no sign: a negative value displays as its two's complement bits at the width of its type, as -1 as i8 in LowerHex is ff.

Implementation RadixDisplay for u32#

silk
impl RadixDisplay for u32

Operation displayRadix#

silk
effect fn displayRadix(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Implementation Display for u64#

silk
impl Display for u64

Operation display#

silk
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the value in the base of Format.style, decimal by default. Sign, precision, zero padding, width, fill, and alignment apply.

Details#

The order is: leading fill, sign, base prefix, zeros from the precision or from zeroPad, digits, trailing fill. Only the alternate form writes a base prefix. A base other than decimal writes no sign: a negative value displays as its two's complement bits at the width of its type, as -1 as i8 in LowerHex is ff.

Implementation RadixDisplay for u64#

silk
impl RadixDisplay for u64

Operation displayRadix#

silk
effect fn displayRadix(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Implementation Display for usize#

silk
impl Display for usize

Operation display#

silk
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the value in the base of Format.style, decimal by default. Sign, precision, zero padding, width, fill, and alignment apply.

Details#

The order is: leading fill, sign, base prefix, zeros from the precision or from zeroPad, digits, trailing fill. Only the alternate form writes a base prefix. A base other than decimal writes no sign: a negative value displays as its two's complement bits at the width of its type, as -1 as i8 in LowerHex is ff.

Implementation RadixDisplay for usize#

silk
impl RadixDisplay for usize

Operation displayRadix#

silk
effect fn displayRadix(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Implementation Display for i8#

silk
impl Display for i8

Operation display#

silk
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the value in the base of Format.style, decimal by default. Sign, precision, zero padding, width, fill, and alignment apply.

Details#

The order is: leading fill, sign, base prefix, zeros from the precision or from zeroPad, digits, trailing fill. Only the alternate form writes a base prefix. A base other than decimal writes no sign: a negative value displays as its two's complement bits at the width of its type, as -1 as i8 in LowerHex is ff.

Implementation RadixDisplay for i8#

silk
impl RadixDisplay for i8

Operation displayRadix#

silk
effect fn displayRadix(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Implementation Display for i16#

silk
impl Display for i16

Operation display#

silk
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the value in the base of Format.style, decimal by default. Sign, precision, zero padding, width, fill, and alignment apply.

Details#

The order is: leading fill, sign, base prefix, zeros from the precision or from zeroPad, digits, trailing fill. Only the alternate form writes a base prefix. A base other than decimal writes no sign: a negative value displays as its two's complement bits at the width of its type, as -1 as i8 in LowerHex is ff.

Implementation RadixDisplay for i16#

silk
impl RadixDisplay for i16

Operation displayRadix#

silk
effect fn displayRadix(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Implementation Display for i32#

silk
impl Display for i32

Operation display#

silk
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the value in the base of Format.style, decimal by default. Sign, precision, zero padding, width, fill, and alignment apply.

Details#

The order is: leading fill, sign, base prefix, zeros from the precision or from zeroPad, digits, trailing fill. Only the alternate form writes a base prefix. A base other than decimal writes no sign: a negative value displays as its two's complement bits at the width of its type, as -1 as i8 in LowerHex is ff.

Implementation RadixDisplay for i32#

silk
impl RadixDisplay for i32

Operation displayRadix#

silk
effect fn displayRadix(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Implementation Display for i64#

silk
impl Display for i64

Operation display#

silk
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the value in the base of Format.style, decimal by default. Sign, precision, zero padding, width, fill, and alignment apply.

Details#

The order is: leading fill, sign, base prefix, zeros from the precision or from zeroPad, digits, trailing fill. Only the alternate form writes a base prefix. A base other than decimal writes no sign: a negative value displays as its two's complement bits at the width of its type, as -1 as i8 in LowerHex is ff.

Implementation RadixDisplay for i64#

silk
impl RadixDisplay for i64

Operation displayRadix#

silk
effect fn displayRadix(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Implementation Display for isize#

silk
impl Display for isize

Operation display#

silk
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the value in the base of Format.style, decimal by default. Sign, precision, zero padding, width, fill, and alignment apply.

Details#

The order is: leading fill, sign, base prefix, zeros from the precision or from zeroPad, digits, trailing fill. Only the alternate form writes a base prefix. A base other than decimal writes no sign: a negative value displays as its two's complement bits at the width of its type, as -1 as i8 in LowerHex is ff.

Implementation RadixDisplay for isize#

silk
impl RadixDisplay for isize

Operation displayRadix#

silk
effect fn displayRadix(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Implementation Display for f64#

silk
impl Display for f64

Operation display#

silk
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the shortest decimal that parses back to the same bits. If the options set a precision, writes exactly that many fractional digits instead.

Details#

The default output parses back to the same value with Format.f64Value. Negative zero displays as -0. Style.LowerExp and Style.UpperExp write scientific notation, such as 1.25e3. Sign, width, fill, alignment, and zero padding apply.

Gotchas#

NaN displays as NaN, and infinity displays as Infinity with a sign from the sign rule, in every style. Both ignore precision and pad with the fill character, never with zeros.

Implementation ExponentDisplay for f64#

silk
impl ExponentDisplay for f64

Operation displayExponent#

silk
effect fn displayExponent(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Implementation Display for f32#

silk
impl Display for f32

Operation display#

silk
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the shortest decimal that parses back to the same bits. If the options set a precision, writes exactly that many fractional digits instead.

Details#

The default output parses back to the same value with Format.f32Value. Negative zero displays as -0. Style.LowerExp and Style.UpperExp write scientific notation, such as 1.25e3. Sign, width, fill, alignment, and zero padding apply. The digits come from the f32 value, so they can differ from the digits of the nearest f64.

Gotchas#

NaN displays as NaN, and infinity displays as Infinity with a sign from the sign rule, in every style. Both ignore precision and pad with the fill character, never with zeros.

Implementation ExponentDisplay for f32#

silk
impl ExponentDisplay for f32

Operation displayExponent#

silk
effect fn displayExponent(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Implementation Display for string<'text>#

silk
impl<'text> Display for string<'text>

Operation display#

silk
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the string with the width, fill, alignment, and precision of the options.

Details#

The default alignment is left. A precision cuts the string to that many Unicode scalars.

Implementation Display for bool#

silk
impl Display for bool

Operation display#

silk
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes true or false as text, with the width, fill, and alignment of the options. The default alignment is left.

Implementation Display for char#

silk
impl Display for char

Operation display#

silk
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the character as text, with the width, fill, and alignment of the options. The default alignment is left.

Implementation Debug for string<'text>#

silk
impl<'text> Debug for string<'text>

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the string in double quotes, with \", \\, \n, \r, \t, \0, and \u{..} escapes, as Rust does. Characters above ASCII are written as they are.

Gotchas#

The width, fill, and precision do not apply.

Implementation Debug for char#

silk
impl Debug for char

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the character in single quotes, with the escapes of string and \'.

Implementation Debug for Option<T>#

silk
impl<T: Debug> Debug for Option<T>

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes None, or Some( and the Debug form of the value and ).

Implementation Debug for Result<T, E>#

silk
impl<T: Debug, E: Debug> Debug for Result<T, E>

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes Success( or Failure(, the Debug form of the payload, and ).

Implementation Debug for &'a [T]#

silk
impl<'a, T: Debug> Debug for &'a [T]

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the Debug form of each element, as [1, 2, 3]. See Format.debugList.

Implementation Debug for &'a mut [T]#

silk
impl<'a, T: Debug> Debug for &'a mut [T]

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the Debug form of each element, as [1, 2, 3]. See Format.debugList.

Implementation Debug for List<T>#

silk
impl<T: Debug> Debug for List<T>

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the Debug form of each element between [ and ], separated by , , as [1, 2, 3]. The alternate form puts each element on its own line.

Implementation Debug for bool#

silk
impl Debug for bool

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the same text as Display.

Implementation Debug for u8#

silk
impl Debug for u8

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the same text as Display.

Implementation Debug for u16#

silk
impl Debug for u16

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the same text as Display.

Implementation Debug for u32#

silk
impl Debug for u32

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the same text as Display.

Implementation Debug for u64#

silk
impl Debug for u64

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the same text as Display.

Implementation Debug for usize#

silk
impl Debug for usize

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the same text as Display.

Implementation Debug for i8#

silk
impl Debug for i8

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the same text as Display.

Implementation Debug for i16#

silk
impl Debug for i16

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the same text as Display.

Implementation Debug for i32#

silk
impl Debug for i32

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the same text as Display.

Implementation Debug for i64#

silk
impl Debug for i64

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the same text as Display.

Implementation Debug for isize#

silk
impl Debug for isize

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the same text as Display.

Implementation Debug for f32#

silk
impl Debug for f32

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the same text as Display, but a whole number ends in .0, as 1.0 and -0.0, so that it reads as a float. A set precision writes the same text as Display.

Implementation Debug for f64#

silk
impl Debug for f64

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the same text as Display, but a whole number ends in .0, as 1.0 and -0.0, so that it reads as a float. A set precision writes the same text as Display.

Category: Text.

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2.

View the source of this page