Enum Value

Source
pub enum Value<'a> {
    Undefined,
    Null,
    Number(f64),
    Bool(bool),
    String(String<'a>),
    Regex(Box<RegexLiteral>),
    Array(Vec<'a, &'a Value<'a>>, ArrayFlags),
    Object(HashMap<String<'a>, &'a Value<'a>, DefaultHashBuilder, &'a Bump>),
    Range(Range<'a>),
    Lambda {
        ast: Box<'a, Ast>,
        input: &'a Value<'a>,
        frame: Frame<'a>,
    },
    NativeFn {
        name: String,
        arity: usize,
        func: fn(FunctionContext<'a, '_>, &[&'a Value<'a>]) -> Result<&'a Value<'a>>,
    },
    Transformer {
        pattern: Box<Ast>,
        update: Box<Ast>,
        delete: Option<Box<Ast>>,
    },
}
Expand description

The core value type for input, output and evaluation.

There’s a lot of lifetimes here to avoid cloning any part of the input that should be kept in the output, avoiding heap allocations for every Value, and allowing structural sharing.

Values are all allocated in a Bump arena, making them contiguous in memory and further avoiding heap allocations for every one.

Variants§

§

Undefined

§

Null

§

Number(f64)

§

Bool(bool)

§

String(String<'a>)

§

Regex(Box<RegexLiteral>)

§

Array(Vec<'a, &'a Value<'a>>, ArrayFlags)

§

Object(HashMap<String<'a>, &'a Value<'a>, DefaultHashBuilder, &'a Bump>)

§

Range(Range<'a>)

§

Lambda

Fields

§ast: Box<'a, Ast>
§input: &'a Value<'a>
§frame: Frame<'a>
§

NativeFn

Fields

§name: String
§arity: usize
§func: fn(FunctionContext<'a, '_>, &[&'a Value<'a>]) -> Result<&'a Value<'a>>
§

Transformer

Fields

§pattern: Box<Ast>
§update: Box<Ast>
§delete: Option<Box<Ast>>

Implementations§

Source§

impl<'a> Value<'a>

Source

pub fn undefined() -> &'a Value<'a>

Source

pub fn null(arena: &Bump) -> &mut Value<'_>

Source

pub fn bool(value: bool) -> &'a Value<'a>

Source

pub fn number(arena: &Bump, value: impl Into<f64>) -> &mut Value<'_>

Source

pub fn number_from_u128(arena: &Bump, value: u128) -> Result<&mut Value<'_>>

Source

pub fn string(arena: &'a Bump, value: &str) -> &'a mut Value<'a>

Source

pub fn array(arena: &Bump, flags: ArrayFlags) -> &mut Value<'_>

Source

pub fn array_from( arena: &'a Bump, arr: BumpVec<'a, &'a Value<'a>>, flags: ArrayFlags, ) -> &'a mut Value<'a>

Source

pub fn array_with_capacity( arena: &Bump, capacity: usize, flags: ArrayFlags, ) -> &mut Value<'_>

Source

pub fn object(arena: &Bump) -> &mut Value<'_>

Source

pub fn object_from<H>( hash: &HashMap<BumpString<'a>, &'a Value<'a>, H, &'a Bump>, arena: &'a Bump, ) -> &'a mut Value<'a>

Source

pub fn object_with_capacity(arena: &Bump, capacity: usize) -> &mut Value<'_>

Source

pub fn lambda( arena: &'a Bump, node: &Ast, input: &'a Value<'a>, frame: Frame<'a>, ) -> &'a mut Value<'a>

Source

pub fn nativefn( arena: &'a Bump, name: &str, arity: usize, func: fn(FunctionContext<'a, '_>, &[&'a Value<'a>]) -> Result<&'a Value<'a>>, ) -> &'a mut Value<'a>

Source

pub fn transformer( arena: &'a Bump, pattern: &Box<Ast>, update: &Box<Ast>, delete: &Option<Box<Ast>>, ) -> &'a mut Value<'a>

Source

pub fn range(arena: &'a Bump, start: isize, end: isize) -> &'a mut Value<'a>

Source

pub fn range_from(arena: &'a Bump, range: &'a Range<'_>) -> &'a mut Value<'a>

Source

pub fn is_undefined(&self) -> bool

Source

pub fn is_null(&self) -> bool

Source

pub fn is_bool(&self) -> bool

Source

pub fn is_number(&self) -> bool

Source

pub fn is_integer(&self) -> bool

Source

pub fn is_array_of_valid_numbers(&self) -> Result<bool>

Source

pub fn is_array_of_strings(&self) -> bool

Source

pub fn is_valid_number(&self) -> Result<bool>

Source

pub fn is_nan(&self) -> bool

Source

pub fn is_finite(&self) -> bool

Source

pub fn is_string(&self) -> bool

Source

pub fn is_array(&self) -> bool

Source

pub fn is_object(&self) -> bool

Source

pub fn is_function(&self) -> bool

Source

pub fn is_truthy(&'a self) -> bool

Source

pub fn get_member(&self, index: usize) -> &'a Value<'a>

Source

pub fn members(&'a self) -> MemberIterator<'a>

Source

pub fn entries(&self) -> Iter<'_, BumpString<'a>, &'a Value<'_>>

Source

pub fn arity(&self) -> usize

Source

pub fn as_bool(&self) -> bool

Source

pub fn as_f64(&self) -> f64

Source

pub fn as_usize(&self) -> usize

Source

pub fn as_isize(&self) -> isize

Source

pub fn as_str(&self) -> Cow<'_, str>

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn get_entry(&self, key: &str) -> &'a Value<'a>

Source

pub fn remove_entry(&mut self, key: &str)

Source

pub fn push(&mut self, value: &'a Value<'a>)

Source

pub fn insert(&mut self, key: &str, value: &'a Value<'a>)

Source

pub fn remove(&mut self, key: &str)

Source

pub fn flatten(&'a self, arena: &'a Bump) -> &'a mut Value<'a>

Source

pub fn wrap_in_array( arena: &'a Bump, value: &'a Value<'a>, flags: ArrayFlags, ) -> &'a mut Value<'a>

Source

pub fn wrap_in_array_if_needed( arena: &'a Bump, value: &'a Value<'a>, flags: ArrayFlags, ) -> &'a Value<'a>

Source

pub fn get_flags(&self) -> ArrayFlags

Source

pub fn has_flags(&self, check_flags: ArrayFlags) -> bool

Source

pub fn clone(&'a self, arena: &'a Bump) -> &'a mut Value<'a>

Source

pub fn clone_array_with_flags( &self, arena: &'a Bump, flags: ArrayFlags, ) -> &'a mut Value<'a>

Source

pub fn serialize(&'a self, pretty: bool) -> String

Source

pub fn __very_unsafe_make_mut(&'a self) -> &'a mut Value<'a>

Trait Implementations§

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 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<'a> Index<&str> for Value<'a>

Source§

type Output = Value<'a>

The returned type after indexing.
Source§

fn index(&self, index: &str) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a> Index<usize> for Value<'a>

Source§

type Output = Value<'a>

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl PartialEq<&str> for Value<'_>

Source§

fn eq(&self, other: &&str) -> 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 PartialEq<bool> for Value<'_>

Source§

fn eq(&self, other: &bool) -> 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 PartialEq<isize> for Value<'_>

Source§

fn eq(&self, other: &isize) -> 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 PartialEq<usize> for Value<'_>

Source§

fn eq(&self, other: &usize) -> 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<'a> PartialEq for Value<'a>

Source§

fn eq(&self, other: &Value<'a>) -> 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 Eq for Value<'_>

Auto Trait Implementations§

§

impl<'a> Freeze for Value<'a>

§

impl<'a> !RefUnwindSafe for Value<'a>

§

impl<'a> !Send for Value<'a>

§

impl<'a> !Sync for Value<'a>

§

impl<'a> Unpin for Value<'a>

§

impl<'a> !UnwindSafe for Value<'a>

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<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<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> 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V