structstd.zon.stringify.Serializer.Struct[src]

Writes ZON structs field by field.

Fields

container: Container

Functions

Functionend[src]

pub fn end(self: *Struct) Writer.Error!void

Finishes serializing the struct.

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

Parameters

self: *Struct

Source Code

Source code
pub fn end(self: *Struct) Writer.Error!void {
    try self.container.end();
    self.* = undefined;
}

Functionfield[src]

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

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

Parameters

self: *Struct
name: []const u8
options: ValueOptions

Source Code

Source code
pub fn field(
    self: *Struct,
    name: []const u8,
    val: anytype,
    options: ValueOptions,
) Writer.Error!void {
    try self.container.field(name, val, options);
}

FunctionfieldMaxDepth[src]

pub fn fieldMaxDepth( self: *Struct, name: []const u8, val: anytype, options: ValueOptions, depth: usize, ) (Writer.Error || error{ExceededMaxDepth})!void

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

Parameters

self: *Struct
name: []const u8
options: ValueOptions
depth: usize

Source Code

Source code
pub fn fieldMaxDepth(
    self: *Struct,
    name: []const u8,
    val: anytype,
    options: ValueOptions,
    depth: usize,
) (Writer.Error || error{ExceededMaxDepth})!void {
    try self.container.fieldMaxDepth(name, val, options, depth);
}

FunctionfieldArbitraryDepth[src]

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

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

Parameters

self: *Struct
name: []const u8
options: ValueOptions

Source Code

Source code
pub fn fieldArbitraryDepth(
    self: *Struct,
    name: []const u8,
    val: anytype,
    options: ValueOptions,
) Writer.Error!void {
    try self.container.fieldArbitraryDepth(name, val, options);
}

FunctionbeginStructField[src]

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

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

Parameters

self: *Struct
name: []const u8

Source Code

Source code
pub fn beginStructField(
    self: *Struct,
    name: []const u8,
    options: SerializeContainerOptions,
) Writer.Error!Struct {
    try self.fieldPrefix(name);
    return self.container.serializer.beginStruct(options);
}

FunctionbeginTupleField[src]

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

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

Parameters

self: *Struct
name: []const u8

Source Code

Source code
pub fn beginTupleField(
    self: *Struct,
    name: []const u8,
    options: SerializeContainerOptions,
) Writer.Error!Tuple {
    try self.fieldPrefix(name);
    return self.container.serializer.beginTuple(options);
}

FunctionfieldPrefix[src]

pub fn fieldPrefix(self: *Struct, name: []const u8) Writer.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.

Parameters

self: *Struct
name: []const u8

Source Code

Source code
pub fn fieldPrefix(self: *Struct, name: []const u8) Writer.Error!void {
    try self.container.fieldPrefix(name);
}

Source Code

Source code
pub const Struct = struct {
    container: Container,

    fn begin(parent: *Self, options: SerializeContainerOptions) Writer.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) Writer.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,
    ) Writer.Error!void {
        try self.container.field(name, val, options);
    }

    /// Serialize a field. Equivalent to calling `fieldPrefix` followed by `valueMaxDepth`.
    pub fn fieldMaxDepth(
        self: *Struct,
        name: []const u8,
        val: anytype,
        options: ValueOptions,
        depth: usize,
    ) (Writer.Error || error{ExceededMaxDepth})!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,
    ) Writer.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: SerializeContainerOptions,
    ) Writer.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: SerializeContainerOptions,
    ) Writer.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) Writer.Error!void {
        try self.container.fieldPrefix(name);
    }
}