Skip to documentation
SLOP

tiny.preserves.AnyEmbedded

Reference tiny.preserves AnyEmbedded

Defined in embedded_mod.

An embedded value that points to a payload of the host program, with optional functions to compare, hash, free and copy it.

API (9)

Actions

Public operations.

Fields and members

Public fields and members.

No direct callersNo direct callsembedded_modAnyEmbedded
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Source: lib/preserves/src/embedded.zig:58

zig
/// An embedded value that points to a payload of the host program, with optional functions to/// compare, hash, free and copy it. Code that places host objects inside values uses this type, as/// the text parser, the JSON codec and every function at the package root do. Every optional part/// defaults to `null`, so `.{ .value = ptr }` is a borrowed payload that compares by address.pub const AnyEmbedded = struct {    /// An untyped pointer to the payload.    value: *anyopaque,    /// The payload's table of equality, hash and order functions, or `null` to compare, order and    /// hash by address.    semantic_ops: ?*const SemanticOps = null,    /// The function that frees the payload, or `null` for a payload the tree borrows. `deinit`    /// calls it with the payload and the allocator.    deinit_fn: ?*const fn (*anyopaque, Allocator) void = null,    /// The function that copies the payload with an allocator and returns a pointer to the copy, or    /// `null`. A payload with a free function and no copy function makes `clone` panic.    clone_fn: ?*const fn (*anyopaque, Allocator) Allocator.Error!*anyopaque = null,    /// Returns whether two embedded values are equal. `Value.eql` calls it for two embedded values.    /// Two values with no table are equal when they point to the same payload. A value with a table    /// never equals one without a table or one with a different table. Two values with the same    /// table are equal when the table's equality says so.    pub fn eql(a: AnyEmbedded, b: AnyEmbedded) bool {        const a_ops = a.semantic_ops orelse {            if (b.semantic_ops != null) return false;            return a.value == b.value;        };        const b_ops = b.semantic_ops orelse return false;        if (a_ops != b_ops) return false;        return a_ops.eql(a.value, b.value);    }    /// Returns the order of one embedded value against another. `Value.compare` calls it for two    /// embedded values. A value with no table orders before one with a table, and two values with    /// no table order by payload address. Values with different tables order by the tables'    /// addresses, and values with the same table order by that table's order. The order is total    /// whenever each table's order is.    pub fn order(a: AnyEmbedded, b: AnyEmbedded) std.math.Order {        const a_ops = a.semantic_ops orelse {            if (b.semantic_ops != null) return .lt;            return std.math.order(@intFromPtr(a.value), @intFromPtr(b.value));        };        const b_ops = b.semantic_ops orelse return .gt;        if (a_ops != b_ops) {            return std.math.order(@intFromPtr(a_ops), @intFromPtr(b_ops));        }        return a_ops.order(a.value, b.value);    }    /// Returns the table's hash of the payload, or the payload's address when there is no table.    /// `Value.hash` calls it for an embedded value.    pub fn hash(self: AnyEmbedded) u64 {        if (self.semantic_ops) |ops| return ops.hash(self.value);        return @intFromPtr(self.value);    }    /// Calls the free function with the payload and `allocator` when there is one, and does nothing    /// otherwise. `Value.deinit` calls it for an embedded value.    pub fn deinit(self: *AnyEmbedded, allocator: Allocator) void {        if (self.deinit_fn) |deinit_payload| deinit_payload(self.value, allocator);    }    /// Returns a copy that keeps the same table and functions. `cloneValueDeep` calls it for an    /// embedded value. With a copy function, the copy points to a new payload from that function.    /// With no copy function and no free function, the copy points to the same payload. With a free    /// function and no copy function, the call panics, because two trees would then free one    /// payload.    pub fn clone(self: AnyEmbedded, allocator: Allocator) Allocator.Error!AnyEmbedded {        var cloned = self;        if (self.clone_fn) |clone_payload| {            cloned.value = try clone_payload(self.value, allocator);            return cloned;        }        if (self.deinit_fn != null) @panic("owned embedded value missing clone hook");        return cloned;    }};

Source: lib/preserves/src/root.zig:160

zig
pub const AnyEmbedded = embedded_mod.AnyEmbedded;
Called byCallsNo direct callstest sourcelib.preserves.src.embeddedtest: AnyEmbedded dispatches through ...test sourcelib.preserves.src.embeddedtest: AnyEmbedded falls back to point...Embeddedeql
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallsNo direct callstest sourcelib.preserves.src.embeddedtest: AnyEmbedded dispatches through ...test sourcelib.preserves.src.embeddedtest: AnyEmbedded falls back to point...Embeddedhash
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallsNo direct callstest sourcelib.preserves.src.embeddedtest: AnyEmbedded dispatches through ...test sourcelib.preserves.src.embeddedtest: AnyEmbedded falls back to point...Embeddedorder
Static calls · unresolved targets: 0 · external targets: 1.

Also reachable as

Embedded, constructors_mod.AnyEmbedded, json.AnyEmbedded, patterns_mod.AnyEmbedded, records_mod.AnyEmbedded, text.AnyEmbedded.

Audit

Definitions6
Public names48
Members4
Version26.7.0
Revisiondaab053ee433