logos.lang.writ.dview

Module lang · package logos-lang

Traits

traitDatum

trait Datum

Presents a type as a DView — the capture seam from a concrete value to its storage form.

Implemented by: i64 u64 bool String

Types

structDView

struct DView

Non-owning, type-erased view: borrowed object bytes plus a (space, code) tag and metadata. Does not extend lifetimes; to own a runtime-typed value use the Writ container (WAny).

Implements: Copy Datatype Container ContainerOrd

Fields

len: u64
meta: u64
obj: *const u8
tag: u64

Methods

fn as_str(self: &DView) -> &[u8]

Materializes a str over the view’s bytes; borrows the same bytes the view does (valid for the view’s lifetime). No tag check.

fn compare(self: &DView, other: &DView) -> Ordering

Compares two views’ object bytes via the shared tag-keyed layer (htag_cmp). Dispatches on self.tag; both views must carry the same tag.

fn drop_store(s: *mut DViewStore) -> void
fn from_parts(obj: *const u8, len: u64, tag: u64, meta: u64) -> DView

Creates a view from explicit parts (for in-container views: a stored object + tag).

fn from_str(s: &[u8]) -> DView

Type-erases a string into a W_STRING view over its UTF-8 bytes (borrows s). Dedicated because str is unsized (a {ptr,len} fat value) and can’t ride the generic from<T>; the byte block IS the Writ String content, so it stays in the Writ space.

fn is_a(self: &DView) -> bool

Returns whether the view’s tag equals T’s Datum tag.

fn meta_word(self: &DView) -> u64

Returns the packed per-value metadata word (0 if none).

fn new_store() -> DViewStore
fn obj_len(self: &DView) -> u64

Returns the object byte length.

fn obj_ptr(self: &DView) -> *const u8

Returns the borrowed pointer to the object bytes.

fn store_accepts(s: *const DViewStore, v: DView) -> bool
fn store_get(s: *const DViewStore, idx: u64) -> DView
fn store_insert_at(s: *mut DViewStore, idx: u64, v: DView) -> void
fn store_len(s: *const DViewStore) -> u64
fn store_push(s: *mut DViewStore, v: DView) -> void
fn store_remove_at(s: *mut DViewStore, idx: u64) -> void
fn store_set(s: *mut DViewStore, idx: u64, v: DView) -> void
fn to(self: &DView) -> T

Materializes a T from the view without a tag check; a mismatched tag reads garbage.

fn try_to(self: &DView) -> Option

Materializes a T from the view if the tag matches; None on a tag mismatch.

fn type_code(self: &DView) -> u64

Returns the full tag word (code-space selector + code).

structDViewStore

struct DViewStore

Variable-width, aligned, owning at-rest store for DView elements (backs Buffer<DView>). Homogeneous: the first stored element declares the container’s tag/meta. storage_get returns a view INTO the arena — valid only until the arena reallocates.

Implements: Storage OwningStorage DynamicStorage

Fields

data: PrimVec<u8>
meta: u64
offsets: PrimVec<u64>
tag: u64

Methods

fn storage_clear(s: *mut DViewStore) -> void
fn storage_drop(s: *mut DViewStore) -> void
fn storage_get(s: *const DViewStore, idx: u64) -> DView
fn storage_insert_at(s: *mut DViewStore, idx: u64, v: DView) -> void
fn storage_len(s: *const DViewStore) -> u64
fn storage_new() -> DViewStore
fn storage_push(s: *mut DViewStore, v: DView) -> void
fn storage_remove_at(s: *mut DViewStore, idx: u64) -> void
fn storage_set(s: *mut DViewStore, idx: u64, v: DView) -> void

Functions

fndv_code

fn dv_code(tag: u64) -> u64

Returns the within-space code (low 56 bits) of a DView tag.

fndv_make_tag

fn dv_make_tag(space: u8, code: u64) -> u64

Packs (space, code) into a DView tag; code is truncated to its low 56 bits.

fndv_space

fn dv_space(tag: u64) -> u8

Returns the code-space selector (high 8 bits) of a DView tag.

fnfrom

fn from(v: &T) -> DView

Type-erases a concrete value into a non-owning view (borrows v) by asking the type to present its storage form. T is inferred (DView::from(&v)).

fnhtag_align

fn htag_align(tag: u64, meta: u64) -> u64

Returns the required alignment of a tag’s object bytes (a power of two). The Buffer aligns every element’s entry to this so in-place reads (to::<T> pointer-casts, a byte-copied compactified Writ object) are valid.

fnhtag_cmp

fn htag_cmp(tag: u64, meta: u64, a: *const u8, alen: u64, b: *const u8, blen: u64) -> Ordering

Compares two same-tagged object-byte runs (total order), dispatched on (space, code). Only the Writ space (0) is wired today; unrecognized codes fall back to unsigned LE compare. Reads via LE byte assembly, so possibly-unaligned borrowed offsets are fine.

fnhtag_size

fn htag_size(tag: u64, meta: u64) -> u64

Returns the object byte stride for a tag (the at-rest/store path); 0 = unknown.