Functions

fn allocPrint(allocator: mem.Allocator, comptime fmt: []const u8, args: anytype) AllocPrintError![]u8

No documentation provided.

fn allocPrintZ(allocator: mem.Allocator, comptime fmt: []const u8, args: anytype) AllocPrintError![:0]u8

No documentation provided.

fn bufPrint(buf: []u8, comptime fmt: []const u8, args: anytype) BufPrintError![]u8

print a Formatter string into buf. Actually just a thin wrapper around `format…

print a Formatter string into buf. Actually just a thin wrapper around format and fixedBufferStream. returns a slice of the bytes printed to.

fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, case: Case, options: FormatOptions) []u8

No documentation provided.

fn bufPrintZ(buf: []u8, comptime fmt: []const u8, args: anytype) BufPrintError![:0]u8

No documentation provided.

fn bytesToHex(input: anytype, case: Case) [input.len * 2]u8

Encodes a sequence of bytes as hexadecimal digits. Returns an array containing …

Encodes a sequence of bytes as hexadecimal digits. Returns an array containing the encoded bytes.

fn charToDigit(c: u8, base: u8) error{InvalidCharacter}!u8

No documentation provided.

inline fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt, args):0]u8

No documentation provided.

fn count(comptime fmt: []const u8, args: anytype) u64

Count the characters needed for format. Useful for preallocating memory

fn defaultSpec(comptime T: type) [:0]const u8

No documentation provided.

fn digitToChar(digit: u8, case: Case) u8

No documentation provided.

fn fmtDuration(ns: u64) Formatter(formatDuration)

Return a Formatter for number of nanoseconds according to its magnitude: [#y][#…

Return a Formatter for number of nanoseconds according to its magnitude: [#y][#w][#d][#h][#m]#[.###][n|u|m]s

fn fmtDurationSigned(ns: i64) Formatter(formatDurationSigned)

Return a Formatter for number of nanoseconds according to its signed magnitude: …

Return a Formatter for number of nanoseconds according to its signed magnitude: [#y][#w][#d][#h][#m]#[.###][n|u|m]s

fn fmtIntSizeBin(value: u64) field_call

Return a Formatter for a u64 value representing a file size. This formatter rep…

Return a Formatter for a u64 value representing a file size. This formatter represents the number as multiple of 1024 and uses the IEC measurement units (KiB, MiB, GiB, …).

fn fmtIntSizeDec(value: u64) field_call

Return a Formatter for a u64 value representing a file size. This formatter rep…

Return a Formatter for a u64 value representing a file size. This formatter represents the number as multiple of 1000 and uses the SI measurement units (kB, MB, GB, …).

fn fmtSliceEscapeLower(bytes: []const u8) field_call

Return a Formatter for a []const u8 where every non-printable ASCII character i…

Return a Formatter for a []const u8 where every non-printable ASCII character is escaped as \xNN, where NN is the character in lowercase hexadecimal notation.

fn fmtSliceEscapeUpper(bytes: []const u8) field_call

Return a Formatter for a []const u8 where every non-printable ASCII character i…

Return a Formatter for a []const u8 where every non-printable ASCII character is escaped as \xNN, where NN is the character in uppercase hexadecimal notation.

fn fmtSliceHexLower(bytes: []const u8) field_call

Return a Formatter for a []const u8 where every byte is formatted as a pair of …

Return a Formatter for a []const u8 where every byte is formatted as a pair of lowercase hexadecimal digits.

fn fmtSliceHexUpper(bytes: []const u8) field_call

Return a Formatter for a []const u8 where every byte is formatted as pair of up…

Return a Formatter for a []const u8 where every byte is formatted as pair of uppercase hexadecimal digits.

fn format(writer: anytype, comptime fmt: []const u8, args: anytype) !void

Renders fmt string with args, calling writer with slices of bytes. If `writer…

Renders fmt string with args, calling writer with slices of bytes. If writer returns an error, the error is returned from format and writer is not called again.

The format string must be comptime-known and may contain placeholders following this format: {[argument][specifier]:[fill][alignment][width].[precision]}

Above, each word including its surrounding [ and ] is a parameter which you have to replace with something:

  • argument is either the numeric index or the field name of the argument that should be inserted
    • when using a field name, you are required to enclose the field name (an identifier) in square brackets, e.g. {[score]…} as opposed to the numeric index form which can be written e.g. {2…}
  • specifier is a type-dependent formatting option that determines how a type should formatted (see below)
  • fill is a single character which is used to pad the formatted text
  • alignment is one of the three characters <, ^, or > to make the text left-, center-, or right-aligned, respectively
  • width is the total width of the field in characters
  • precision specifies how many decimals a formatted number should have

Note that most of the parameters are optional and may be omitted. Also you can leave out separators like : and . when all parameters after the separator are omitted. Only exception is the fill parameter. If fill is required, one has to specify alignment as well, as otherwise the digits after : is interpreted as width, not fill.

The specifier has several options for types:

  • x and X: output numeric value in hexadecimal notation
  • s:
    • for pointer-to-many and C pointers of u8, print as a C-string using zero-termination
    • for slices of u8, print the entire slice as a string without zero-termination
  • e: output floating point value in scientific notation
  • d: output numeric value in decimal notation
  • b: output integer value in binary notation
  • o: output integer value in octal notation
  • c: output integer as an ASCII character. Integer type must have 8 bits at max.
  • u: output integer as an UTF-8 sequence. Integer type must have 21 bits at max.
  • ?: output optional value as either the unwrapped value, or null; may be followed by a format specifier for the underlying value.
  • !: output error union value as either the unwrapped value, or the formatted error value; may be followed by a format specifier for the underlying value.
  • *: output the address of the value instead of the value itself.
  • any: output a value of any type using its default format.

If a formatted user type contains a function of the type

pub fn format(value: ?, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void

with ? being the type formatted, this function will be called instead of the default implementation. This allows user types to be formatted in a logical manner instead of dumping all fields of the type.

A user type may be a struct, vector, union or enum type.

To print literal curly braces, escape them by writing them twice, e.g. {{ or }}.

fn formatAddress(value: anytype, options: FormatOptions, writer: anytype) @TypeOf(writer).Error!void

No documentation provided.

fn formatAsciiChar(c: u8, options: FormatOptions, writer: anytype) !void

No documentation provided.

fn formatBuf(buf: []const u8, options: FormatOptions, writer: anytype) !void

No documentation provided.

fn formatFloatDecimal(value: anytype, options: FormatOptions, writer: anytype) !void

Print a float of the format x.yyyyy where the number of y is specified by the pr…

Print a float of the format x.yyyyy where the number of y is specified by the precision argument. By default floats are printed at full precision (no rounding).

fn formatFloatHexadecimal(value: anytype, options: FormatOptions, writer: anytype) !void

No documentation provided.

fn formatFloatScientific(value: anytype, options: FormatOptions, writer: anytype) !void

Print a float in scientific notation to the specified precision. Null uses full …

Print a float in scientific notation to the specified precision. Null uses full precision. It should be the case that every full precision, printed value can be re-parsed back to the same type unambiguously.

fn formatInt(value: anytype, base: u8, case: Case, options: FormatOptions, writer: anytype) !void

No documentation provided.

fn formatIntBuf(out_buf: []u8, value: anytype, base: u8, case: Case, options: FormatOptions) usize

No documentation provided.

fn formatIntValue(value: anytype, comptime fmt: []const u8, options: FormatOptions, writer: anytype) !void

No documentation provided.

fn formatText(bytes: []const u8, comptime fmt: []const u8, options: FormatOptions, writer: anytype) !void

No documentation provided.

fn formatType(value: anytype, comptime fmt: []const u8, options: FormatOptions, writer: anytype, max_depth: usize) @TypeOf(writer).Error!void

No documentation provided.

fn formatUnicodeCodepoint(c: u21, options: FormatOptions, writer: anytype) !void

No documentation provided.

fn hexToBytes(out: []u8, input: []const u8) ![]u8

Decodes the sequence of bytes represented by the specified string of hexadecima…

Decodes the sequence of bytes represented by the specified string of hexadecimal characters. Returns a slice of the output buffer containing the decoded bytes.

fn invalidFmtError(comptime fmt: []const u8, value: anytype) void

No documentation provided.

fn parseFloat(comptime T: type, s: []const u8) ParseFloatError!T

No documentation provided.

fn parseInt(comptime T: type, buf: []const u8, base: u8) ParseIntError!T

Parses the string buf as signed or unsigned representation in the specified b…

Parses the string buf as signed or unsigned representation in the specified base of an integral value of type T.

When base is zero the string prefix is examined to detect the true base:

  • A prefix of “0b” implies base=2,
  • A prefix of “0o” implies base=8,
  • A prefix of “0x” implies base=16,
  • Otherwise base=10 is assumed.

Ignores ‘_’ character in buf. See also parseUnsigned.

fn parseIntSizeSuffix(buf: []const u8, digit_base: u8) ParseIntError!usize

Parses a number like ‘2G’, ‘2Gi’, or ‘2GiB’.

fn parseUnsigned(comptime T: type, buf: []const u8, base: u8) ParseIntError!T

Parses the string buf as unsigned representation in the specified base of an …

Parses the string buf as unsigned representation in the specified base of an integral value of type T.

When base is zero the string prefix is examined to detect the true base:

  • A prefix of “0b” implies base=2,
  • A prefix of “0o” implies base=8,
  • A prefix of “0x” implies base=16,
  • Otherwise base=10 is assumed.

Ignores ‘_’ character in buf. See also parseInt.

Values

default_max_depth
comptime_int