Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Struct

Struct

Public Struct
std.zon.Serializer.Struct
pub const Struct = struct

Writes ZON structs field by field.

Fields

container: Container

Functions

fn begin(parent: *Serializer, options: ContainerOptions) Error!Struct
pub fn end(self: *Struct) Error!void

Finishes serializing the struct.

Prints a trailing comma as configured when appropriate, and the closing bracket.

pub fn field(self: *Struct, name: []const u8, val: anytype, options: ValueOptions) Error!void

Serialize a field. Equivalent to calling fieldPrefix followed by value.

pub fn fieldMaxDepth(self: *Struct, name: []const u8, val: anytype, options: ValueOptions, depth: usize) DepthError!void

Serialize a field. Equivalent to calling fieldPrefix followed by valueMaxDepth. Returns error.ExceededMaxDepth if depth is exceeded.

pub fn fieldArbitraryDepth(self: *Struct, name: []const u8, val: anytype, options: ValueOptions) Error!void

Serialize a field. Equivalent to calling fieldPrefix followed by valueArbitraryDepth.

pub fn beginStructField(self: *Struct, name: []const u8, options: ContainerOptions) Error!Struct

Starts a field with a struct as a value. Returns the struct.

pub fn beginTupleField(self: *Struct, name: []const u8, options: ContainerOptions) Error!Tuple

Starts a field with a tuple as a value. Returns the tuple.

pub fn fieldPrefix(self: *Struct, name: []const u8) Error!void

Print a field prefix. This prints any necessary commas, the field name (escaped if necessary) and whitespace as configured. Useful if you want to serialize the field value yourself.

File

zon/Serializer.zig:623
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
pub const Struct = struct {
    container: Container,

    fn begin(parent: *Serializer, options: ContainerOptions) Error!Struct {
        return .{
            .container = try Container.begin(parent, .named, options),
        };
    }

    /// Finishes serializing the struct.
    ///
    /// Prints a trailing comma as configured when appropriate, and the closing bracket.
    pub fn end(self: *Struct) Error!void {
        try self.container.end();
        self.* = undefined;
    }

    /// Serialize a field. Equivalent to calling `fieldPrefix` followed by `value`.
    pub fn field(
        self: *Struct,
        name: []const u8,
        val: anytype,
        options: ValueOptions,
    ) Error!void {
        try self.container.field(name, val, options);
    }

    /// Serialize a field. Equivalent to calling `fieldPrefix` followed by `valueMaxDepth`.
    /// Returns `error.ExceededMaxDepth` if `depth` is exceeded.
    pub fn fieldMaxDepth(
        self: *Struct,
        name: []const u8,
        val: anytype,
        options: ValueOptions,
        depth: usize,
    ) DepthError!void {
        try self.container.fieldMaxDepth(name, val, options, depth);
    }

    /// Serialize a field. Equivalent to calling `fieldPrefix` followed by
    /// `valueArbitraryDepth`.
    pub fn fieldArbitraryDepth(
        self: *Struct,
        name: []const u8,
        val: anytype,
        options: ValueOptions,
    ) Error!void {
        try self.container.fieldArbitraryDepth(name, val, options);
    }

    /// Starts a field with a struct as a value. Returns the struct.
    pub fn beginStructField(
        self: *Struct,
        name: []const u8,
        options: ContainerOptions,
    ) Error!Struct {
        try self.fieldPrefix(name);
        return self.container.serializer.beginStruct(options);
    }

    /// Starts a field with a tuple as a value. Returns the tuple.
    pub fn beginTupleField(
        self: *Struct,
        name: []const u8,
        options: ContainerOptions,
    ) Error!Tuple {
        try self.fieldPrefix(name);
        return self.container.serializer.beginTuple(options);
    }

    /// Print a field prefix. This prints any necessary commas, the field name (escaped if
    /// necessary) and whitespace as configured. Useful if you want to serialize the field
    /// value yourself.
    pub fn fieldPrefix(self: *Struct, name: []const u8) Error!void {
        try self.container.fieldPrefix(name);
    }
}