pub struct Value { /* private fields */ }Expand description
Value-model re-exports: the word, its payload, type descriptors, and the
export hook live in crate::value, the single representation for
every type.
Implementations§
Source§impl Value
impl Value
Sourcepub fn descriptor(&self) -> &'static TypeDescriptor
pub fn descriptor(&self) -> &'static TypeDescriptor
The word’s canonical descriptor singleton: the vtable backing its lifecycle and operations.
Sourcepub fn type_name(&self) -> &'static str
pub fn type_name(&self) -> &'static str
The word’s registered type name (the descriptor’s name).
Sourcepub fn inline_bits(&self) -> u64
pub fn inline_bits(&self) -> u64
Raw payload bits, copied out. Meaningful for inline words (the value’s bytes); for heap words these are the box pointer’s bits.
Sourcepub fn heap_ptr(&self) -> *mut ()
pub fn heap_ptr(&self) -> *mut ()
Heap box (exclusive) or buffer (shared) pointer, copied out. Only meaningful for heap words; never dereferenced here. Reading (not dereferencing) is safe.
Sourcepub fn mint_inline<T>(descriptor: &'static TypeDescriptor, value: T) -> Value
pub fn mint_inline<T>(descriptor: &'static TypeDescriptor, value: T) -> Value
Mint an inline word: memcpy the value’s bytes into the payload.
Zero allocation. The descriptor must be the payload type’s own
OxDockType::descriptor(); mismatching them misdirects the vtable
and is unsound.
Sourcepub fn mint_heap<T>(descriptor: &'static TypeDescriptor, value: T) -> Value
pub fn mint_heap<T>(descriptor: &'static TypeDescriptor, value: T) -> Value
Mint an exclusive heap word: move the value into an owned Box<T>
behind a thin pointer. One box allocation. The descriptor must be the
payload type’s own OxDockType::descriptor(); mismatching them
misdirects the vtable and is unsound.
Mint a shared heap word: move the value into a reference-counted
Arc<T> behind a thin pointer. One allocation; later clones bump the
strong count instead of copying. The descriptor must be the payload
type’s own OxDockType::descriptor() built for the shared path
(#[oxdock_type(shared)]); mismatching them misdirects the vtable
and is unsound.
Sourcepub fn read_inline<T>(&self, expected: &'static TypeDescriptor) -> Option<T>
pub fn read_inline<T>(&self, expected: &'static TypeDescriptor) -> Option<T>
Read an inline word back out. Returns None when the word carries
a different descriptor; the load itself is infallible for a word
minted for T.
Sourcepub fn read_heap<T>(&self, expected: &'static TypeDescriptor) -> Option<&T>
pub fn read_heap<T>(&self, expected: &'static TypeDescriptor) -> Option<&T>
Borrow a heap word’s concrete value. Returns None when the word
carries a different descriptor.
Sourcepub fn read_heap_mut<T>(
&mut self,
expected: &'static TypeDescriptor,
) -> Option<&mut T>
pub fn read_heap_mut<T>( &mut self, expected: &'static TypeDescriptor, ) -> Option<&mut T>
Borrow a heap word’s concrete value mutably, detaching shared buffers
first (copy-on-write). Returns None when the word carries a
different descriptor. This is the only sound way to obtain &mut
access to a heap payload: exclusive heaps hand out their box
directly, shared heaps clone-then-hand-out when the strong count
exceeds 1 and mutate in place otherwise. Panics when called with an
inline descriptor, which has no heap buffer.
Sourcepub fn list(items: Vec<Value>) -> Value
pub fn list(items: Vec<Value>) -> Value
Construct a list word (shared heap: clones share the buffer).
Sourcepub fn map(entries: BTreeMap<String, Value>) -> Value
pub fn map(entries: BTreeMap<String, Value>) -> Value
Construct a map word (shared heap: clones share the buffer).
Sourcepub fn pipe_fresh() -> Value
pub fn pipe_fresh() -> Value
Construct a fresh unbound pipe handle (LET $p: PIPE, host
new_pipe()). Materializes lazily on first binding.
Sourcepub fn pipe_fresh_in_task(task_id: u64) -> Value
pub fn pipe_fresh_in_task(task_id: u64) -> Value
Construct a fresh unbound pipe handle declared by task_id (0 =
root flow). The id travels with every clone so promotion checks
always see the declaration origin.
Sourcepub fn pipe_handle(handle: PipeHandle) -> Value
pub fn pipe_handle(handle: PipeHandle) -> Value
Wrap an existing handle as a PIPE word. Clones share the backend.
Sourcepub fn semaphore(max: usize) -> Value
pub fn semaphore(max: usize) -> Value
Construct a semaphore word admitting at most max concurrent
holders. Every clone names the same backend.
Sourcepub fn permit(sem: &Arc<SemaphoreState>) -> Value
pub fn permit(sem: &Arc<SemaphoreState>) -> Value
Mint a PERMIT word bound to sem. The permit returns to the
semaphore when the last clone of the word drops.
Sourcepub fn as_semaphore(&self) -> Option<Arc<SemaphoreState>>
pub fn as_semaphore(&self) -> Option<Arc<SemaphoreState>>
Borrow the semaphore backend out of a SEMAPHORE word. Returns
None for non-SEMAPHORE words. The clone shares the backend.
Sourcepub fn as_handle(&self) -> Option<u64>
pub fn as_handle(&self) -> Option<u64>
Read a task-handle payload. Returns None for non-HANDLE words.
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Borrow a string payload. Returns None for non-STRING words.
Sourcepub fn as_list(&self) -> Option<&Vec<Value>>
pub fn as_list(&self) -> Option<&Vec<Value>>
Borrow a list payload. Returns None for non-LIST words.
Sourcepub fn as_list_mut(&mut self) -> Option<&mut Vec<Value>>
pub fn as_list_mut(&mut self) -> Option<&mut Vec<Value>>
Borrow a list payload mutably, detaching the shared buffer first when
clones exist. Returns None for non-LIST words. This is the choke
point every future in-place container mutation must go through.
Sourcepub fn as_map(&self) -> Option<&BTreeMap<String, Value>>
pub fn as_map(&self) -> Option<&BTreeMap<String, Value>>
Borrow a map payload. Returns None for non-MAP words.
Sourcepub fn as_map_mut(&mut self) -> Option<&mut BTreeMap<String, Value>>
pub fn as_map_mut(&mut self) -> Option<&mut BTreeMap<String, Value>>
Borrow a map payload mutably, detaching the shared buffer first when
clones exist. Returns None for non-MAP words. This is the choke
point every future in-place container mutation must go through.
Sourcepub fn as_pipe_handle(&self) -> Option<PipeHandle>
pub fn as_pipe_handle(&self) -> Option<PipeHandle>
Clone the pipe handle out of a PIPE word. Returns None for
non-PIPE words. The clone shares the backend cell.
Sourcepub fn as_duration(&self) -> Option<Duration>
pub fn as_duration(&self) -> Option<Duration>
Read a duration payload. Returns None for non-DURATION words.
Trait Implementations§
impl Send for Value
A DSL value: a TypeDescriptor vtable pointer plus a ValuePayload.
Fixed size (128 bits on 64-bit targets). Lifecycle and operations call
the vtable directly, with no table lookup and no lock; see the module
docs for the ownership discipline.