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#
WriterErrorif the ambientWriterfails. The bytes that the writer accepted before the failure stay written. This module does not roll output back.ParseErrorfrom the...Valueparse functions, with the reasonNotANumberorOutOfRange.
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#
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#
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.writerfor theWritereffect that receives the output.silk.io.writer_nativeforStdoutWriterandStderrWriter, which write to standard output and standard error.
Import as Format with import silk.text.format { Format }.
Public declarations: 14.
Format#
pub struct FormatThe 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#
WriterErrorif the ambientWriterfails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.ParseErrorfrom the...Valueparse 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#
impl FormatAssociated function defaultOptions#
pub fn defaultOptions() -> FormatOptionsReturns 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#
pub fn make(options: FormatOptions) -> FormatterReturns 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#
pub fn makeDefault() -> FormatterReturns a Formatter that uses Format.defaultOptions.
Method hasWidth#
pub fn hasWidth(self: &Formatter) -> boolReturns true if the options set a minimum width.
Method width#
pub fn width(self: &Formatter) -> usizeReturns the minimum width in Unicode scalars. Returns 0 if the options set no width.
Method alignment#
pub fn alignment(self: &Formatter) -> AlignmentReturns the alignment of the content inside the width.
Method fill#
pub fn fill(self: &Formatter) -> charReturns the character that fills the space up to the width.
Method sign#
pub fn sign(self: &Formatter) -> SignReturns the sign rule for numbers.
Method style#
pub fn style(self: &Formatter) -> StyleReturns the style that selects the number base or notation.
Method alternate#
pub fn alternate(self: &Formatter) -> boolReturns 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#
pub fn zeroPad(self: &Formatter) -> boolReturns 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#
pub fn hasPrecision(self: &Formatter) -> boolReturns true if the options set a precision.
Method precision#
pub fn precision(self: &Formatter) -> usizeReturns 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#
pub fn color(self: &Formatter) -> boolReturns 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#
pub effect fn write(
self: &mut Formatter,
bytes: &[u8]
) -> () ! WriterError ? &mut WriterWrites bytes to the ambient Writer as they are. It does not apply width or other options.
Errors#
WriterErrorif the ambientWriterfails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.
Method writeText#
pub effect fn writeText(
self: &mut Formatter,
text: string
) -> () ! WriterError ? &mut WriterWrites the UTF-8 bytes of text to the ambient Writer. It does not apply width or other
options.
Errors#
WriterErrorif the ambientWriterfails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.
Method writePadding#
pub effect fn writePadding(
self: &mut Formatter,
count: usize
) -> () ! WriterError ? &mut WriterWrites the fill character count times.
Errors#
WriterErrorif the ambientWriterfails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.
Method leadingPadding#
pub fn leadingPadding(self: &Formatter, contentWidth: usize) -> usizeReturns 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#
pub fn trailingPadding(self: &Formatter, contentWidth: usize) -> usizeReturns 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#
pub effect fn writeLeadingPadding(
self: &mut Formatter,
contentWidth: usize
) -> () ! WriterError ? &mut WriterWrites the fill that goes before content that is contentWidth scalars wide. The count comes
from Format.leadingPadding.
Errors#
WriterErrorif the ambientWriterfails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.
Method writeTrailingPadding#
pub effect fn writeTrailingPadding(
self: &mut Formatter,
contentWidth: usize
) -> () ! WriterError ? &mut WriterWrites the fill that goes after content that is contentWidth scalars wide. The count comes
from Format.trailingPadding.
Errors#
WriterErrorif the ambientWriterfails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.
Method padText#
pub effect fn padText(
self: &mut Formatter,
text: string
) -> () ! WriterError ? &mut WriterWrites 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#
WriterErrorif the ambientWriterfails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.
Method padNumber#
pub effect fn padNumber(
self: &mut Formatter,
negative: bool,
prefix: string,
digits: string
) -> () ! WriterError ? &mut WriterWrites 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#
WriterErrorif the ambientWriterfails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.
Associated function display#
pub effect fn display<T: Display>(value: &T) -> () ! WriterError ? &mut WriterWrites 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#
WriterErrorif the ambientWriterfails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.
Associated function displayWith#
pub effect fn displayWith<T: Display>(
value: &T,
options: FormatOptions
) -> () ! WriterError ? &mut WriterWrites 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#
WriterErrorif the ambientWriterfails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.
Associated function debug#
pub effect fn debug<T: Debug>(value: &T) -> () ! WriterError ? &mut WriterWrites 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#
WriterErrorif the ambientWriterfails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.
Associated function debugWith#
pub effect fn debugWith<T: Debug>(
value: &T,
options: FormatOptions
) -> () ! WriterError ? &mut WriterWrites 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#
WriterErrorif the ambientWriterfails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.
Associated function debugFields#
pub effect fn debugFields<T>(
value: &T,
static name: string<'static>,
formatter: &mut Formatter
) -> () ! WriterError ? &mut WriterWrites 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#
WriterErrorif the ambientWriterfails. 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#
pub effect fn debugList<T: Debug>(
values: &[T],
formatter: &mut Formatter
) -> () ! WriterError ? &mut WriterWrites 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#
WriterErrorif the ambientWriterfails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.
Associated function debugRecord#
pub effect fn debugRecord(
name: string,
formatter: &mut Formatter
) -> DebugRecord ! WriterError ? &mut WriterStarts 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:
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#
WriterErrorif the ambientWriterfails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.
Associated function debugField#
pub effect fn debugField<T: Debug>(
record: &mut DebugRecord,
label: string,
value: &T,
formatter: &mut Formatter
) -> () ! WriterError ? &mut WriterWrites one field of a record that Format.debugRecord started, as label: value.
Errors#
WriterErrorif the ambientWriterfails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.
Associated function debugFinish#
pub effect fn debugFinish(
record: DebugRecord,
formatter: &mut Formatter
) -> () ! WriterError ? &mut WriterEnds a record that Format.debugRecord started. It writes the closing } when the record
has a field.
Errors#
WriterErrorif the ambientWriterfails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.
Associated function format#
pub effect fn format<Args>(
static template: string<'static>,
args: &Args
) -> () ! WriterError ? &mut WriterWrites 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 field1. The same field can show more than one time.{}counts from field0and ignores the{1}placeholders, as in Rust.{name}takes the record fieldname.{{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.+forSign.Always.-is the default and changes nothing.#for the alternate form.0for zero padding.A width in decimal digits, or
1$orw$to take it from the integer field1orw..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 is007; Rust ignores it there.A type:
xlowercase hexadecimal,Xuppercase hexadecimal,ooctal,bbinary. These need an integer, and#adds the prefix0x,0o, or0b.eandEwrite a float in scientific notation, such as1.25e3; these need a float.?writes theDebugform, and#?the prettyDebugform.
The compiler parses the options and checks the template and the fields. A placeholder without
options uses Format.defaultOptions. format borrows args.
Errors#
WriterErrorif the ambientWriterfails. 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#
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#
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#
NotANumberiftextis empty or has a character that is not part of the number. The offset is the position of that character, or the length oftextif a digit is missing at the end.OutOfRangeif the value is more thanu64.MAX.
Associated function signedValue#
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#
NotANumberiftextis empty or has a character that is not part of the number. The offset is the position of that character, or the length oftextif a digit is missing at the end.OutOfRangeif the value is less thani64.MINor more thani64.MAX.
Associated function f64Value#
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#
NotANumberiftextis empty or has a character that is not part of the number. The offset is the position of that character, or the length oftextif 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#
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#
NotANumberiftextis empty or has a character that is not part of the number. The offset is the position of that character, or the length oftextif 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#
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#
NotANumberiftextis empty or has a character that is not part of the number. The offset is the position of that character, or the length oftextif a digit is missing at the end.OutOfRangeif the value is more thanu8.MAX.
Associated function u16Value#
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#
NotANumberiftextis empty or has a character that is not part of the number. The offset is the position of that character, or the length oftextif a digit is missing at the end.OutOfRangeif the value is more thanu16.MAX.
Associated function u32Value#
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#
NotANumberiftextis empty or has a character that is not part of the number. The offset is the position of that character, or the length oftextif a digit is missing at the end.OutOfRangeif the value is more thanu32.MAX.
Associated function u64Value#
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#
NotANumberiftextis empty or has a character that is not part of the number. The offset is the position of that character, or the length oftextif a digit is missing at the end.OutOfRangeif the value is more thanu64.MAX.
Associated function usizeValue#
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#
NotANumberiftextis empty or has a character that is not part of the number. The offset is the position of that character, or the length oftextif a digit is missing at the end.OutOfRangeif the value is more thanusize.MAX.
Associated function i8Value#
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#
NotANumberiftextis empty or has a character that is not part of the number. The offset is the position of that character, or the length oftextif a digit is missing at the end.OutOfRangeif the value is less thani8.MINor more thani8.MAX.
Associated function i16Value#
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#
NotANumberiftextis empty or has a character that is not part of the number. The offset is the position of that character, or the length oftextif a digit is missing at the end.OutOfRangeif the value is less thani16.MINor more thani16.MAX.
Associated function i32Value#
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#
NotANumberiftextis empty or has a character that is not part of the number. The offset is the position of that character, or the length oftextif a digit is missing at the end.OutOfRangeif the value is less thani32.MINor more thani32.MAX.
Associated function i64Value#
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#
NotANumberiftextis empty or has a character that is not part of the number. The offset is the position of that character, or the length oftextif a digit is missing at the end.OutOfRangeif the value is less thani64.MINor more thani64.MAX.
Associated function isizeValue#
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#
NotANumberiftextis empty or has a character that is not part of the number. The offset is the position of that character, or the length oftextif a digit is missing at the end.OutOfRangeif the value is less thanisize.MINor more thanisize.MAX.
Alignment#
pub enum AlignmentWhere 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#
DefaultUses the default of the Display implementation. The standard implementations align numbers
to the right and text to the left.
Left#
LeftPuts the content first and all fill after it.
Center#
CenterPuts half of the fill before the content and half after it. An odd extra fill character goes after it.
Right#
RightPuts all fill before the content.
Sign#
pub enum SignHow numbers that are not negative show a sign.
NegativeOnly#
NegativeOnlyWrites - for negative numbers and no sign for other numbers.
Always#
AlwaysWrites - for negative numbers and + for other numbers, including zero.
Space#
SpaceWrites - for negative numbers and one space for other numbers, so columns of numbers align.
Style#
pub enum StyleThe 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#
DefaultDecimal for integers, and the normal form of other types.
LowerHex#
LowerHexBase 16 with the digits 0 to 9 and a to f.
UpperHex#
UpperHexBase 16 with the digits 0 to 9 and A to F.
Octal#
OctalBase 8.
Binary#
BinaryBase 2.
LowerExp#
LowerExpScientific 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#
UpperExpScientific notation with an uppercase E, such as 1.25E3.
FormatOptions#
pub struct FormatOptionsThe 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#
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#
pub alignment: AlignmentWhere the content goes inside the width.
Field fill#
pub fill: charThe character that fills the space up to the width.
Field sign#
pub sign: SignHow numbers that are not negative show a sign.
Field alternate#
pub alternate: boolPermission for a Display implementation to use its alternate form. The standard integers
use it to write a base prefix such as 0x.
Field zeroPad#
pub zeroPad: boolIf 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#
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#
pub color: boolPermission, not a request, to write ANSI color codes. The standard implementations never write them.
Field style#
pub style: StyleThe base or notation for numbers.
Formatter#
pub struct FormatterThe 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#
pub struct DebugRecordA record that a hand-written Debug implementation is writing. Start one with
Format.debugRecord.
Implementation Copy for DebugRecord#
impl Copy for DebugRecordDisplay#
pub interface DisplayA 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)#
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#
effect fn display(
self: &Self,
formatter: &mut Formatter
) -> () ! WriterError ? &mut WriterWrites self to the ambient Writer with the options in formatter.
Errors#
WriterErrorif the ambientWriterfails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.
RadixDisplay#
pub interface RadixDisplayAn 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#
effect fn displayRadix(
self: &Self,
formatter: &mut Formatter
) -> () ! WriterError ? &mut WriterWrites the value in the base that Format.style selects. A style that is not a base is
decimal.
ExponentDisplay#
pub interface ExponentDisplayA 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#
effect fn displayExponent(
self: &Self,
formatter: &mut Formatter
) -> () ! WriterError ? &mut WriterWrites the value in the notation that Format.style selects. A style that is not
Style.LowerExp or Style.UpperExp writes the normal form.
Debug#
pub interface DebugA 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#
effect fn debug(
self: &Self,
formatter: &mut Formatter
) -> () ! WriterError ? &mut WriterWrites the Debug form of the value through the ambient mutable Writer.
Errors#
WriterErrorif the ambientWriterfails. The bytes that the writer accepted before the failure stay written. Nothing is rolled back.
NotANumber#
pub struct NotANumberThe reason for a ParseError when the text is not a number of the expected form.
Field offset#
pub offset: usizeThe 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#
impl Debug for NotANumberOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the fields, as NotANumber { offset: ... }.
OutOfRange#
pub struct OutOfRangeThe reason for a ParseError when the text is a number but the value does not fit the target
type.
Implementation Debug for OutOfRange#
impl Debug for OutOfRangeOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites OutOfRange.
ParseError#
pub struct ParseErrorThe error from the ...Value parse functions.
Details#
Use match on reason to get NotANumber or OutOfRange.
Field reason#
pub reason: NotANumber | OutOfRangeWhy the text was not accepted.
Implementation Debug for ParseError#
impl Debug for ParseErrorOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the reason, as ParseError { reason: NotANumber { offset: 2 } }.
Implementation Display for u8#
impl Display for u8Operation display#
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites 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#
impl RadixDisplay for u8Operation displayRadix#
effect fn displayRadix(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterImplementation Display for u16#
impl Display for u16Operation display#
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites 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#
impl RadixDisplay for u16Operation displayRadix#
effect fn displayRadix(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterImplementation Display for u32#
impl Display for u32Operation display#
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites 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#
impl RadixDisplay for u32Operation displayRadix#
effect fn displayRadix(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterImplementation Display for u64#
impl Display for u64Operation display#
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites 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#
impl RadixDisplay for u64Operation displayRadix#
effect fn displayRadix(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterImplementation Display for usize#
impl Display for usizeOperation display#
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites 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#
impl RadixDisplay for usizeOperation displayRadix#
effect fn displayRadix(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterImplementation Display for i8#
impl Display for i8Operation display#
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites 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#
impl RadixDisplay for i8Operation displayRadix#
effect fn displayRadix(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterImplementation Display for i16#
impl Display for i16Operation display#
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites 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#
impl RadixDisplay for i16Operation displayRadix#
effect fn displayRadix(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterImplementation Display for i32#
impl Display for i32Operation display#
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites 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#
impl RadixDisplay for i32Operation displayRadix#
effect fn displayRadix(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterImplementation Display for i64#
impl Display for i64Operation display#
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites 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#
impl RadixDisplay for i64Operation displayRadix#
effect fn displayRadix(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterImplementation Display for isize#
impl Display for isizeOperation display#
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites 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#
impl RadixDisplay for isizeOperation displayRadix#
effect fn displayRadix(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterImplementation Display for f64#
impl Display for f64Operation display#
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites 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#
impl ExponentDisplay for f64Operation displayExponent#
effect fn displayExponent(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterImplementation Display for f32#
impl Display for f32Operation display#
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites 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#
impl ExponentDisplay for f32Operation displayExponent#
effect fn displayExponent(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterImplementation Display for string<'text>#
impl<'text> Display for string<'text>Operation display#
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites 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#
impl Display for boolOperation display#
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites true or false as text, with the width, fill, and alignment of the options. The
default alignment is left.
Implementation Display for char#
impl Display for charOperation display#
effect fn display(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the character as text, with the width, fill, and alignment of the options. The default alignment is left.
Implementation Debug for string<'text>#
impl<'text> Debug for string<'text>Operation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites 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#
impl Debug for charOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the character in single quotes, with the escapes of string and \'.
Implementation Debug for Option<T>#
impl<T: Debug> Debug for Option<T>Operation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites None, or Some( and the Debug form of the value and ).
Implementation Debug for Result<T, E>#
impl<T: Debug, E: Debug> Debug for Result<T, E>Operation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites Success( or Failure(, the Debug form of the payload, and ).
Implementation Debug for &'a [T]#
impl<'a, T: Debug> Debug for &'a [T]Operation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the Debug form of each element, as [1, 2, 3]. See Format.debugList.
Implementation Debug for &'a mut [T]#
impl<'a, T: Debug> Debug for &'a mut [T]Operation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the Debug form of each element, as [1, 2, 3]. See Format.debugList.
Implementation Debug for List<T>#
impl<T: Debug> Debug for List<T>Operation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites 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#
impl Debug for boolOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the same text as Display.
Implementation Debug for u8#
impl Debug for u8Operation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the same text as Display.
Implementation Debug for u16#
impl Debug for u16Operation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the same text as Display.
Implementation Debug for u32#
impl Debug for u32Operation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the same text as Display.
Implementation Debug for u64#
impl Debug for u64Operation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the same text as Display.
Implementation Debug for usize#
impl Debug for usizeOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the same text as Display.
Implementation Debug for i8#
impl Debug for i8Operation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the same text as Display.
Implementation Debug for i16#
impl Debug for i16Operation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the same text as Display.
Implementation Debug for i32#
impl Debug for i32Operation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the same text as Display.
Implementation Debug for i64#
impl Debug for i64Operation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the same text as Display.
Implementation Debug for isize#
impl Debug for isizeOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the same text as Display.
Implementation Debug for f32#
impl Debug for f32Operation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites 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#
impl Debug for f64Operation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites 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.