Skip to main content

Value

Struct Value 

Source
pub struct Value(/* private fields */);
Expand description

The core Value type for all Sema data. NaN-boxed: stored as 8 bytes. Floats stored directly, everything else encoded in quiet-NaN payload space.

Implementations§

Source§

impl Value

Source

pub const NIL: Value

Source

pub const TRUE: Value

Source

pub const FALSE: Value

Source

pub fn nil() -> Value

Source

pub fn bool(b: bool) -> Value

Source

pub fn int(n: i64) -> Value

Source

pub fn float(f: f64) -> Value

Source

pub fn char(c: char) -> Value

Source

pub fn symbol_from_spur(spur: Spur) -> Value

Source

pub fn symbol(s: &str) -> Value

Source

pub fn keyword_from_spur(spur: Spur) -> Value

Source

pub fn keyword(s: &str) -> Value

Source

pub fn string(s: &str) -> Value

Source

pub fn string_from_rc(rc: Rc<String>) -> Value

Source

pub fn list(v: Vec<Value>) -> Value

Source

pub fn list_from_rc(rc: Rc<Vec<Value>>) -> Value

Source

pub fn vector(v: Vec<Value>) -> Value

Source

pub fn vector_from_rc(rc: Rc<Vec<Value>>) -> Value

Source

pub fn map(m: BTreeMap<Value, Value>) -> Value

Source

pub fn map_from_rc(rc: Rc<BTreeMap<Value, Value>>) -> Value

Source

pub fn hashmap(entries: Vec<(Value, Value)>) -> Value

Source

pub fn hashmap_from_rc(rc: Rc<HashMap<Value, Value>>) -> Value

Source

pub fn lambda(l: Lambda) -> Value

Source

pub fn lambda_from_rc(rc: Rc<Lambda>) -> Value

Source

pub fn macro_val(m: Macro) -> Value

Source

pub fn macro_from_rc(rc: Rc<Macro>) -> Value

Source

pub fn native_fn(f: NativeFn) -> Value

Source

pub fn native_fn_from_rc(rc: Rc<NativeFn>) -> Value

Source

pub fn prompt(p: Prompt) -> Value

Source

pub fn prompt_from_rc(rc: Rc<Prompt>) -> Value

Source

pub fn message(m: Message) -> Value

Source

pub fn message_from_rc(rc: Rc<Message>) -> Value

Source

pub fn conversation(c: Conversation) -> Value

Source

pub fn conversation_from_rc(rc: Rc<Conversation>) -> Value

Source

pub fn tool_def(t: ToolDefinition) -> Value

Source

pub fn tool_def_from_rc(rc: Rc<ToolDefinition>) -> Value

Source

pub fn agent(a: Agent) -> Value

Source

pub fn agent_from_rc(rc: Rc<Agent>) -> Value

Source

pub fn thunk(t: Thunk) -> Value

Source

pub fn thunk_from_rc(rc: Rc<Thunk>) -> Value

Source

pub fn record(r: Record) -> Value

Source

pub fn record_from_rc(rc: Rc<Record>) -> Value

Source

pub fn bytevector(bytes: Vec<u8>) -> Value

Source

pub fn bytevector_from_rc(rc: Rc<Vec<u8>>) -> Value

Source§

impl Value

Source

pub fn raw_bits(&self) -> u64

Get the raw bits (for debugging/testing).

Source

pub unsafe fn from_raw_bits(bits: u64) -> Value

Construct a Value from raw NaN-boxed bits.

§Safety

Caller must ensure bits represents a valid NaN-boxed value. For immediate types (nil, bool, int, symbol, keyword, char), this is always safe. For heap-pointer types, the encoded pointer must be valid and have its Rc ownership accounted for (i.e., the caller must ensure the refcount is correct).

Source

pub fn raw_tag(&self) -> Option<u64>

Get the NaN-boxing tag of a boxed value (0-63). Returns None for non-boxed values (floats).

Source

pub fn as_native_fn_ref(&self) -> Option<&NativeFn>

Borrow the underlying NativeFn without bumping the Rc refcount. SAFETY: The returned reference is valid as long as this Value is alive.

Source

pub fn is_float(&self) -> bool

Check if this is a float (non-boxed).

Source

pub fn view(&self) -> ValueView

Pattern-match friendly view of this value. For heap types, this bumps the Rc refcount.

Source

pub fn type_name(&self) -> &'static str

Source

pub fn is_nil(&self) -> bool

Source

pub fn is_truthy(&self) -> bool

Source

pub fn is_bool(&self) -> bool

Source

pub fn is_int(&self) -> bool

Source

pub fn is_symbol(&self) -> bool

Source

pub fn is_keyword(&self) -> bool

Source

pub fn is_string(&self) -> bool

Source

pub fn is_list(&self) -> bool

Source

pub fn is_pair(&self) -> bool

Source

pub fn is_vector(&self) -> bool

Source

pub fn is_map(&self) -> bool

Source

pub fn is_lambda(&self) -> bool

Source

pub fn is_native_fn(&self) -> bool

Source

pub fn is_thunk(&self) -> bool

Source

pub fn is_record(&self) -> bool

Source

pub fn as_int(&self) -> Option<i64>

Source

pub fn as_float(&self) -> Option<f64>

Source

pub fn as_bool(&self) -> Option<bool>

Source

pub fn as_str(&self) -> Option<&str>

Source

pub fn as_string_rc(&self) -> Option<Rc<String>>

Source

pub fn as_symbol(&self) -> Option<String>

Source

pub fn as_symbol_spur(&self) -> Option<Spur>

Source

pub fn as_keyword(&self) -> Option<String>

Source

pub fn as_keyword_spur(&self) -> Option<Spur>

Source

pub fn as_char(&self) -> Option<char>

Source

pub fn as_list(&self) -> Option<&[Value]>

Source

pub fn as_list_rc(&self) -> Option<Rc<Vec<Value>>>

Source

pub fn as_vector(&self) -> Option<&[Value]>

Source

pub fn as_vector_rc(&self) -> Option<Rc<Vec<Value>>>

Source

pub fn as_map_rc(&self) -> Option<Rc<BTreeMap<Value, Value>>>

Source

pub fn as_hashmap_rc(&self) -> Option<Rc<HashMap<Value, Value>>>

Source

pub fn as_lambda_rc(&self) -> Option<Rc<Lambda>>

Source

pub fn as_macro_rc(&self) -> Option<Rc<Macro>>

Source

pub fn as_native_fn_rc(&self) -> Option<Rc<NativeFn>>

Source

pub fn as_thunk_rc(&self) -> Option<Rc<Thunk>>

Source

pub fn as_record(&self) -> Option<&Record>

Source

pub fn as_record_rc(&self) -> Option<Rc<Record>>

Source

pub fn as_bytevector(&self) -> Option<&[u8]>

Source

pub fn as_bytevector_rc(&self) -> Option<Rc<Vec<u8>>>

Source

pub fn as_prompt_rc(&self) -> Option<Rc<Prompt>>

Source

pub fn as_message_rc(&self) -> Option<Rc<Message>>

Source

pub fn as_conversation_rc(&self) -> Option<Rc<Conversation>>

Source

pub fn as_tool_def_rc(&self) -> Option<Rc<ToolDefinition>>

Source

pub fn as_agent_rc(&self) -> Option<Rc<Agent>>

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Value

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Hash for Value

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Value

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Value

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for Value

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.