Skip to main content

Value

Enum Value 

Source
pub enum Value {
    Null,
    Bool(bool),
    Int(i64),
    UInt(u64),
    Float(f64),
    Str(Arc<str>),
    List(Arc<[Value]>),
    Map(Arc<Map>),
    Function(Arc<NativeFunction>),
}
Expand description

One expression value.

Values are immutable and cheap to clone: strings, lists, maps and functions are behind an Arc.

PartialEq is the expression language’s == (see Value::equals), so a host comparing values in Rust compares them the way the workflow does.

Variants§

§

Null

§

Bool(bool)

§

Int(i64)

A 64-bit integer: what an integer literal is, and what +, -, *, / and % stay in while both operands are ints.

§

UInt(u64)

An integer above i64::MAX — what JSON gives a host for one, since a JSON integer is an i64 or a u64 and nothing else represents u64::MAX exactly. A value this wide is never produced from a literal and only ever shows up injected; arithmetic that mixes it with an int is exact.

§

Float(f64)

A 64-bit float. Mixed int/float arithmetic produces a float.

§

Str(Arc<str>)

§

List(Arc<[Value]>)

§

Map(Arc<Map>)

An injected object. a.b reads a member, a['b'] the same key.

§

Function(Arc<NativeFunction>)

An injected method. f(x) calls it directly, a.f(x) calls it with a as its first argument, and a function stored in a map is called the same way when reached through that map.

Implementations§

Source§

impl Value

Source

pub fn function<F>(f: F) -> Value
where F: Fn(&[Value]) -> Result<Value> + Send + Sync + 'static,

Wrap a closure as an injectable method.

use acts_expr::Value;

let upper = Value::function(|args| match args {
    [Value::Str(s)] => Ok(Value::from(s.to_uppercase())),
    _ => Err(acts_expr::Error::Type { operation: "upper", got: "other" }),
});
Source

pub fn map<K, V, I>(entries: I) -> Value
where K: Into<String>, V: Into<Value>, I: IntoIterator<Item = (K, V)>,

Build an object from key/value pairs.

use acts_expr::Value;

let step = Value::map([("id", Value::from("step1")), ("retries", Value::from(2))]);
Source

pub fn list<I, V>(items: I) -> Value
where I: IntoIterator<Item = V>, V: Into<Value>,

Build a list.

Source

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

The type name the errors and Display use.

Source

pub fn is_null(&self) -> bool

Source

pub fn is_number(&self) -> bool

Whether the value is an int, a uint or a float.

Source

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

Source

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

Source

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

The value as a u64, for an int that is not negative too.

Source

pub fn as_i128(&self) -> Option<i128>

The value as a 128-bit integer: exact for both integer kinds, which is what lets int and uint mix without a rounding step.

Source

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

Source

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

The number as an f64, whatever kind of number it is.

Source

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

Source

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

Source

pub fn as_map(&self) -> Option<&Map>

Source

pub fn is_function(&self) -> bool

Source

pub fn equals(&self, other: &Value) -> bool

Value equality, as == defines it: numbers compare across int and float, null is only equal to null, lists and maps compare element-wise, and values of different kinds are simply not equal.

Source

pub fn compare(&self, other: &Value) -> Option<Ordering>

Ordering for <, <=, > and >=: numbers across int and float, and strings by their bytes. None for every other pair, which the evaluator reports as a type error.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 Default for Value

Source§

fn default() -> Self

Returns the “default value” for a type. 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 From<&str> for Value

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<()> for Value

Source§

fn from(_: ()) -> Self

Converts to this type from the input type.
Source§

impl From<Arc<str>> for Value

Source§

fn from(value: Arc<str>) -> Self

Converts to this type from the input type.
Source§

impl From<HashMap<String, Value>> for Value

Source§

fn from(value: Map) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Value>> From<Option<T>> for Value

Source§

fn from(value: Option<T>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Value>> for Value

Source§

fn from(value: Vec<Value>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Value

Source§

fn from(value: u64) -> Self

A u64 that fits an i64 becomes one, so a uint only ever holds a value that needs the wider type.

Source§

impl From<usize> for Value

Source§

fn from(value: usize) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Value

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Value

§

impl !UnwindSafe for Value

§

impl Forget for Value

§

impl Freeze for Value

§

impl Move for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin 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<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 = !

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

fn try_from(value: U) -> Result<T, !>

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.