pub struct Value { /* private fields */ }Expand description
A handle to a RayforceDB object (atom, vector, list, dict, table, …).
§Confined to its scope
A Value points into the engine heap, and tearing the runtime down unmaps
that heap — ray_runtime_destroy munmaps every pool without consulting any
object’s reference count, so a surviving handle would point at unmapped
address space, not at freed bytes. There is no check that could make such a
handle safe to read; only never producing one can.
crate::Runtime::scope is what never produces one. The closure is handed a
&Runtime it cannot drop, and its Send bounds reject a Value leaving by
return or by capture — so every Value is dropped before the heap it lives
in goes away.
§Safety
!Send/!Sync, and must stay so — twice over. The core’s VM is
thread-local, so a value on another thread would release against the wrong
heap; and Runtime::scope’s bounds are spelled in terms of Send, so this
marker is also what confines a value to its scope.
fn assert_send<T: Send>() {}
assert_send::<rayforce::Value>();fn assert_sync<T: Sync>() {}
assert_sync::<rayforce::Value>();Control — compile_fail passes on any build failure, a rename included:
fn assert_exists<T>() {}
assert_exists::<rayforce::Value>();Implementations§
Source§impl Value
impl Value
Source§impl Value
impl Value
Source§impl Value
impl Value
Sourcepub fn name_ref(name: &str) -> Value
pub fn name_ref(name: &str) -> Value
A symbol atom used as a name reference (column / global-env lookup):
the ATTR_QUOTED flag is cleared so the query compiler resolves it by
name rather than treating it as a literal symbol.
Sourcepub fn time_millis(ms: i32) -> Value
pub fn time_millis(ms: i32) -> Value
A time atom: raw milliseconds since midnight.
Sourcepub fn timestamp_nanos(ns: i64) -> Value
pub fn timestamp_nanos(ns: i64) -> Value
A timestamp atom: raw nanoseconds since 2000-01-01 UTC.
Sourcepub fn typed_null(abs_type: i8) -> Value
pub fn typed_null(abs_type: i8) -> Value
A typed null atom for the given canonical type id (e.g. sys::RAY_I64).
Sourcepub fn is_atom_null(&self) -> bool
pub fn is_atom_null(&self) -> bool
True if this atom is a (typed or untyped) null.
Sourcepub fn as_date_days(&self) -> Result<i32>
pub fn as_date_days(&self) -> Result<i32>
Read a date atom as raw days since 2000-01-01.
Sourcepub fn as_time_millis(&self) -> Result<i32>
pub fn as_time_millis(&self) -> Result<i32>
Read a time atom as raw milliseconds since midnight.
Sourcepub fn as_timestamp_nanos(&self) -> Result<i64>
pub fn as_timestamp_nanos(&self) -> Result<i64>
Read a timestamp atom as raw nanoseconds since 2000-01-01 UTC.
Source§impl Value
impl Value
Sourcepub fn attrs(&self) -> u8
pub fn attrs(&self) -> u8
The value’s attribute byte.
Rarely needed — the typed accessors cover the normal cases. The
exception is telling a keyed table apart from a plain list: it decodes
as a 2-element list carrying RAY_ATTR_DICT, which no type code
distinguishes.
Sourcepub fn null() -> Value
pub fn null() -> Value
The untyped null singleton (RAY_NULL_OBJ).
__ray_null is a static in the C library, not a pool block, so it is
unaffected by the heap’s teardown. Retain and release are no-ops for it
in the core too.
Sourcepub fn type_code(&self) -> i8
pub fn type_code(&self) -> i8
The signed type tag (negative = atom, positive = vector, 0 = list, …).
Sourcepub fn len_raw(&self) -> i64
pub fn len_raw(&self) -> i64
Element / pair count for vectors, lists, and dicts; for other objects the
raw len field (not meaningful for atoms).
Sourcepub fn serialize(&self) -> Result<Vec<u8>>
pub fn serialize(&self) -> Result<Vec<u8>>
Serialize to a byte vector (core wire format with IPC header).
Sourcepub fn deserialize(bytes: &[u8]) -> Result<Value>
pub fn deserialize(bytes: &[u8]) -> Result<Value>
Deserialize a value from bytes previously produced by Value::serialize
(or another Rayforce wire-format encoder).
Source§impl Value
impl Value
Sourcepub fn vec<T: VecElem>(data: &[T]) -> Value
pub fn vec<T: VecElem>(data: &[T]) -> Value
Build a vector from a slice of fixed-width elements: a single memcpy,
followed by one pass over the payload that raises HAS_NULLS if it
already holds the type’s sentinel — see Value::is_null_at.
Sourcepub fn bool_vec(data: &[bool]) -> Value
pub fn bool_vec(data: &[bool]) -> Value
Build a boolean vector (RAY_BOOL) from a slice of bool.
Sourcepub fn sym_vec<S: AsRef<str>>(items: &[S]) -> Value
pub fn sym_vec<S: AsRef<str>>(items: &[S]) -> Value
Build a symbol vector, interning each string.
Sourcepub fn empty_vec(abs_type: i8, capacity: i64) -> Value
pub fn empty_vec(abs_type: i8, capacity: i64) -> Value
Allocate an empty vector of the given canonical type with capacity.
Sourcepub fn as_slice<T: VecElem>(&self) -> Result<&[T]>
pub fn as_slice<T: VecElem>(&self) -> Result<&[T]>
Zero-copy view of a fixed-width vector’s storage as &[T].
Errors if the vector’s element type doesn’t match T. The slice borrows
self, so it cannot outlive the vector.
Sourcepub fn bool_slice(&self) -> Result<&[u8]>
pub fn bool_slice(&self) -> Result<&[u8]>
Zero-copy view of a boolean vector’s storage (each byte is 0 or 1).
Sourcepub fn date_days_slice(&self) -> Result<&[i32]>
pub fn date_days_slice(&self) -> Result<&[i32]>
Zero-copy view of a date vector as raw days since 2000-01-01.
Sourcepub fn time_millis_slice(&self) -> Result<&[i32]>
pub fn time_millis_slice(&self) -> Result<&[i32]>
Zero-copy view of a time vector as raw milliseconds since midnight.
Sourcepub fn timestamp_nanos_slice(&self) -> Result<&[i64]>
pub fn timestamp_nanos_slice(&self) -> Result<&[i64]>
Zero-copy view of a timestamp vector as raw nanoseconds since 2000-01-01 UTC.
Sourcepub fn is_null_at(&self, idx: usize) -> bool
pub fn is_null_at(&self, idx: usize) -> bool
True if element idx is null.
Nulls are in-band. For the sentinel-encoded types (i16/i32/i64,
f32/f64, date/time/timestamp, GUID) the core first consults the
vector’s HAS_NULLS attribute — raised by Value::vec when the raw
payload already holds a sentinel, and by Value::set_null — and only
then compares the element against its sentinel (i64::MIN, NaN, the
all-zero GUID, …). Symbol and string vectors skip the gate: the empty
symbol and the empty string are their nulls. bool/u8 vectors are
never null.
Because of the gate, a numeric sentinel written later through
Value::set or Value::push is not reported here; the boxed atom
still answers Value::is_atom_null, which is why
to_vec::<Option<T>>() maps it to None either way. Use set_null to
null an element.
Sourcepub fn get(&self, idx: usize) -> Result<Value>
pub fn get(&self, idx: usize) -> Result<Value>
Box element idx as a Value. Bounds-checked.
Null elements of the sentinel-encoded types (integers, floats,
temporals, GUID) come back as the untyped null singleton
(Value::is_null). Symbol and string vectors carry their null
in-band, so an empty element comes back as the empty atom:
Value::is_atom_null is true for it and Option<String> extraction
yields None, while plain String extraction still succeeds.
Sourcepub fn to_vec<T: FromValue>(&self) -> Result<Vec<T>>
pub fn to_vec<T: FromValue>(&self) -> Result<Vec<T>>
Collect all elements, converting each via crate::FromValue.
Sourcepub fn set<T: VecElem>(&mut self, idx: usize, elem: T) -> Result<()>
pub fn set<T: VecElem>(&mut self, idx: usize, elem: T) -> Result<()>
Overwrite element idx with a fixed-width value.
Sourcepub fn set_null(&mut self, idx: usize, is_null: bool) -> Result<()>
pub fn set_null(&mut self, idx: usize, is_null: bool) -> Result<()>
Mark element idx as null: writes the type’s sentinel into the payload
(i64::MIN, NaN, symbol id 0, the empty string, the all-zero GUID)
and raises HAS_NULLS so Value::is_null_at reports it. Rejected for
bool/u8 vectors and for slices.
is_null = false is a no-op in the core — it cannot know the prior real
value — so the sentinel stays and the element remains null until the
caller overwrites it with Value::set.