[−][src]Enum wlambda::vval::VVal
VVal aka. VariantValue is a data structure to represent all kinds of WLambda data structures.
It's used for the AST, for internal data and for runtime data structures.
Variants
The none value, the default value of all non initialized data.
The err value is a special sentinel value for representing any kind of
application error condition. It's created using the special $e
Bol(bool)
Representation of a boolean value.
Representation of an interned string aka symbol or key.
Representation of a unicode/text string.
Representation of a byte buffer.
Int(i64)
Integer value
Flt(f64)
Float value
Syn(SynPos)
A syntax node in the AST, records the position too.
A pair
An optional value. While VVal::None basically has the same meaning as "no value", an optional value provides functions a way to say that they don't even return none value but nothing. Yes, it sounds weird, and it is weird. But in case of iterator functions that iterate over an array you can find out whether the iterator is at the end or will provide more values.
A special internal iterator type for built in VVal data structures.
A list (or vector) of VVals.
Map(Rc<RefCell<FnvHashMap<Symbol, VVal>>>)
A mapping of strings to VVals.
A function, see also VValFun
A guarded VVal, that executes a given function when it is no longer referenced.
A numerical (mathematical) vector storing integers. See NVec for more information.
A numerical (mathematical) vector storing floats. See NVec for more information.
A (strong) reference to a VVal.
A hidden strong reference to a VVal. Generated either explicitly by $&
or if a variable is captured by a closure.
A (weak) reference to a VVal. Might turn VVal::None anytime.
Usr(Box<dyn VValUserData>)
A vval that can box some user data which can later be accessed from inside user supplied Rust functions via std::any::Any.
Implementations
impl VVal
[src]
pub fn new_str(s: &str) -> VVal
[src]
pub fn new_str_mv(s: String) -> VVal
[src]
pub fn new_sym(s: &str) -> VVal
[src]
pub fn new_sym_mv(s: String) -> VVal
[src]
pub fn new_byt(v: Vec<u8>) -> VVal
[src]
pub fn err(v: VVal, pos: SynPos) -> VVal
[src]
pub fn err_msg(s: &str) -> VVal
[src]
pub fn vec() -> VVal
[src]
pub fn vec1(a: VVal) -> VVal
[src]
pub fn vec2(a: VVal, b: VVal) -> VVal
[src]
pub fn vec3(a: VVal, b: VVal, c: VVal) -> VVal
[src]
pub fn opt(v: VVal) -> VVal
[src]
pub fn opt_none() -> VVal
[src]
pub fn pair(a: VVal, b: VVal) -> VVal
[src]
pub fn to_vec(&self) -> Vec<VVal>
[src]
pub fn vec_from(vl: &[VVal]) -> VVal
[src]
pub fn vec_mv(v: Vec<VVal>) -> VVal
[src]
pub fn call(&self, env: &mut Env, args: &[VVal]) -> Result<VVal, StackAction>
[src]
pub fn compare_str(&self, b: &VVal) -> Ordering
[src]
pub fn shallow_clone(&self) -> VVal
[src]
pub fn compare_num(&self, b: &VVal) -> Ordering
[src]
pub fn sort<F>(&self, compare: F) where
F: FnMut(&VVal, &VVal) -> Ordering,
[src]
F: FnMut(&VVal, &VVal) -> Ordering,
pub fn fisher_yates_shuffle<I>(&mut self, rand: I) where
I: FnMut() -> i64,
[src]
I: FnMut() -> i64,
pub fn keys(&self) -> VVal
[src]
pub fn values(&self) -> VVal
[src]
pub fn enumerate(&self) -> VVal
[src]
pub fn iter_over_vvals(&self) -> bool
[src]
Returns true if this vval is containing (multiple) other VVals. Usually true for: Maps, Vectors, Pairs and Opt.
Helpful if you want to iterate through a data structure by recursively iterating over a vval. Without getting iterations over individual string characters.
pub fn iter(&self) -> VValIter
[src]
This function returns you an iterator over the VVal. It will iterate over data such as VVal::Str, VVal::Sym, VVal::Lst, VVal::Map and VVal::Byt.
This functionality provides the for
keyword/function in WLambda.
use wlambda::*; let some_vec = VVal::vec(); some_vec.push(VVal::Int(10)); some_vec.push(VVal::Int(22)); some_vec.push(VVal::Int(36)); let mut sum = 0; for (v, _) in some_vec.iter() { sum += v.i(); } assert_eq!(sum, 68);
pub fn disable_function_arity(&self) -> VVal
[src]
This method will disable all arity checks of the function in the VVal. Does nothing if the VVal is not a function.
It is used for disabling checks of drop functions, as they are evaluated in their own environment and there is no proper way to report errors upwards.
pub fn clone_and_rebind_upvalues<T>(&self, f: T) -> VVal where
T: FnOnce(&Vec<VarPos>, &mut Vec<VVal>),
[src]
T: FnOnce(&Vec<VarPos>, &mut Vec<VVal>),
This function is an internal function that clones a function reference and assigns new upvalues to it for making a new closure instance.
pub fn call_no_args(&self, env: &mut Env) -> Result<VVal, StackAction>
[src]
pub fn call_internal(
&self,
env: &mut Env,
argc: usize
) -> Result<VVal, StackAction>
[src]
&self,
env: &mut Env,
argc: usize
) -> Result<VVal, StackAction>
pub fn to_ref(&self) -> VVal
[src]
[src]
pub fn assign_ref(&mut self, value: VVal)
[src]
pub fn set_ref(&self, v: VVal) -> VVal
[src]
pub fn hide_ref(self) -> VVal
[src]
pub fn upgrade(self) -> VVal
[src]
pub fn downgrade(self) -> VVal
[src]
pub fn map() -> VVal
[src]
pub fn map1(k: &str, v: VVal) -> VVal
[src]
pub fn map2(k: &str, v: VVal, k2: &str, v2: VVal) -> VVal
[src]
pub fn map3(k: &str, v: VVal, k2: &str, v2: VVal, k3: &str, v3: VVal) -> VVal
[src]
pub fn sym(s: &str) -> VVal
[src]
pub fn to_sym(&self) -> Symbol
[src]
pub fn ref_id(&self) -> Option<i64>
[src]
pub fn eqv(&self, v: &VVal) -> bool
[src]
pub fn map_ok_skip<T, R>(&self, op: T, skip: usize) -> Vec<R> where
T: FnMut(&VVal) -> R,
[src]
T: FnMut(&VVal) -> R,
pub fn map_skip<R, E, T>(&self, op: T, skip: usize) -> Result<Vec<R>, E> where
T: FnMut(&VVal) -> Result<R, E>,
[src]
T: FnMut(&VVal) -> Result<R, E>,
pub fn unshift(&self, val: VVal) -> &VVal
[src]
pub fn insert_at(&self, index: usize, val: VVal)
[src]
pub fn set(&self, index: usize, val: VVal)
[src]
pub fn set_at(&self, index: usize, val: VVal)
[src]
pub fn at(&self, index: usize) -> Option<VVal>
[src]
pub fn proto_data(&self) -> VVal
[src]
pub fn proto_lookup(&self, key: &str) -> Option<VVal>
[src]
pub fn get_key_sym(&self, key: &Symbol) -> Option<VVal>
[src]
pub fn get_key(&self, key: &str) -> Option<VVal>
[src]
pub fn set_map_key_fun<T>(
&self,
key: &str,
fun: T,
min_args: Option<usize>,
max_args: Option<usize>,
err_arg_ok: bool
) where
T: 'static + Fn(&mut Env, usize) -> Result<VVal, StackAction>,
[src]
&self,
key: &str,
fun: T,
min_args: Option<usize>,
max_args: Option<usize>,
err_arg_ok: bool
) where
T: 'static + Fn(&mut Env, usize) -> Result<VVal, StackAction>,
pub fn deref(&self) -> VVal
[src]
pub fn with_deref<O, D, R>(&self, op: O, default: D) -> R where
O: FnOnce(&VVal) -> R,
D: FnOnce(Option<&VVal>) -> R,
[src]
O: FnOnce(&VVal) -> R,
D: FnOnce(Option<&VVal>) -> R,
pub fn list_operation<O, R>(&self, op: O) -> Result<R, StackAction> where
O: FnMut(&mut RefMut<Vec<VVal>>) -> R,
[src]
O: FnMut(&mut RefMut<Vec<VVal>>) -> R,
pub fn delete_key(&self, key: &VVal) -> Result<VVal, StackAction>
[src]
pub fn set_key_str(&self, key: &str, val: VVal) -> Result<(), StackAction>
[src]
pub fn set_key_sym(&self, key: Symbol, val: VVal) -> Result<(), StackAction>
[src]
pub fn set_key(&self, key: &VVal, val: VVal) -> Result<(), StackAction>
[src]
pub fn pop(&self) -> VVal
[src]
pub fn accum(&mut self, val: &VVal)
[src]
pub fn push(&self, val: VVal) -> &VVal
[src]
pub fn is_empty(&self) -> bool
[src]
pub fn len(&self) -> usize
[src]
pub fn s_len(&self) -> usize
[src]
pub fn s_raw(&self) -> String
[src]
Returns the string data or converts the value to a string for displaying. The conversion format is not for reading the value in again via the WLambda parser, it's for accessing the data as pure as possible.
Use this if you need the raw unescaped contents of VVal::Str, VVal::Sym, VVal::Byt and other VVals.
As this is used usually for generating output a VVal::None is turned into an empty string
There is also with_s_ref()
which allows you to work with a
reference to the string, in case you don't need to own the copy!
use wlambda::VVal; assert_eq!(VVal::None.s_raw(), ""); assert_eq!(VVal::new_str("Test").s_raw(), "Test");
pub fn with_s_ref<T, R>(&self, f: T) -> R where
T: FnOnce(&str) -> R,
[src]
T: FnOnce(&str) -> R,
Like s_raw() but returns a reference to the string.
Use this if you need the raw unescaped contents of VVal::Str, VVal::Sym, VVal::Byt and other VVals.
As this is used usually for generating output a VVal::None is turned into an empty string
use wlambda::VVal; VVal::None.with_s_ref( |s: &str| assert_eq!(s, "")); VVal::new_str("Test").with_s_ref( |s: &str| assert_eq!(s, "Test"));
pub fn is_float(&self) -> bool
[src]
pub fn is_int(&self) -> bool
[src]
pub fn is_sym(&self) -> bool
[src]
pub fn is_syn(&self) -> bool
[src]
pub fn get_syn_pos(&self) -> SynPos
[src]
pub fn set_syn(&mut self, syn: Syntax)
[src]
pub fn set_syn_at(&self, idx: usize, syn: Syntax)
[src]
pub fn get_syn(&self) -> Syntax
[src]
pub fn compile_err(&self, msg: String) -> CompileError
[src]
pub fn to_compile_err(&self, msg: String) -> Result<EvalNode, CompileError>
[src]
pub fn is_pair(&self) -> bool
[src]
pub fn is_iter(&self) -> bool
[src]
pub fn is_optional(&self) -> bool
[src]
pub fn is_ref(&self) -> bool
[src]
pub fn is_wref(&self) -> bool
[src]
pub fn is_bool(&self) -> bool
[src]
pub fn is_bytes(&self) -> bool
[src]
pub fn is_str(&self) -> bool
[src]
pub fn is_fun(&self) -> bool
[src]
pub fn is_vec(&self) -> bool
[src]
pub fn is_nvec(&self) -> bool
[src]
pub fn is_ivec(&self) -> bool
[src]
pub fn is_fvec(&self) -> bool
[src]
pub fn nvec_len(&self) -> usize
[src]
pub fn is_map(&self) -> bool
[src]
pub fn is_some(&self) -> bool
[src]
pub fn is_none(&self) -> bool
[src]
pub fn is_err(&self) -> bool
[src]
pub fn type_name(&self) -> &str
[src]
pub fn v_(&self, idx: usize) -> VVal
[src]
Quick access method for retrieving the VVal at index idx
.
Returns VVal::None if the VVal is not a VVal::Lst or no such index exists.
See also the shorthands v_i
, v_f
, v_s
and v_s_raw
.
use wlambda::VVal; let v = VVal::vec(); v.push(VVal::Int(10)); v.push(VVal::Int(11)); assert_eq!(v.v_(1).i(), 11); assert_eq!(v.v_i(1), 11);
pub fn v_k(&self, key: &str) -> VVal
[src]
Quick access method for retrieving the VVal at key idx
.
Returns VVal::None if the VVal is not a VVal::Map or no such index exists.
See also the shorthands v_ik
, v_fk
, v_sk
and v_s_rawk
.
use wlambda::VVal; let v = VVal::map(); v.set_key_str("aaa", VVal::Int(12)); v.set_key_str("abc", VVal::Int(13)); v.set_key_str("zyy", VVal::Int(14)); assert_eq!(v.v_k("abc").i(), 13); assert_eq!(v.v_ik("aaa"), 12); assert_eq!(v.v_ik("zyy"), 14);
pub fn v_i(&self, idx: usize) -> i64
[src]
Quick access of an integer at the given idx
.
See also v_
.
let v = wlambda::VVal::vec(); v.push(wlambda::VVal::Int(11)); assert_eq!(v.v_i(0), 11);
pub fn v_ik(&self, key: &str) -> i64
[src]
Quick access of the integer at the given key
.
See also v_k
.
let v = wlambda::VVal::map(); v.set_key_str("aaa", wlambda::VVal::new_str("10")); assert_eq!(v.v_ik("aaa"), 10);
pub fn v_s_raw(&self, idx: usize) -> String
[src]
Quick access of a raw string at the given idx
.
See also v_
.
let v = wlambda::VVal::vec(); v.push(wlambda::VVal::Int(12)); assert_eq!(v.v_s_raw(0), "12");
pub fn v_with_s_ref<T, R>(&self, idx: usize, f: T) -> R where
T: FnOnce(&str) -> R,
[src]
T: FnOnce(&str) -> R,
Quick access of a raw string as reference at the given idx
.
See also v_
.
let v = wlambda::VVal::vec(); v.push(wlambda::VVal::new_str("12")); assert_eq!(v.v_with_s_ref(0, |s: &str| s.chars().nth(0).unwrap()), '1');
pub fn v_s_rawk(&self, key: &str) -> String
[src]
Quick access of the string at the given key
.
See also v_k
.
let v = wlambda::VVal::map(); v.set_key_str("aaa", wlambda::VVal::new_str("XYX")); assert_eq!(v.v_s_rawk("aaa"), "XYX");
pub fn v_with_s_refk<T, R>(&self, key: &str, f: T) -> R where
T: FnOnce(&str) -> R,
[src]
T: FnOnce(&str) -> R,
Quick access of the string as reference at the given key
.
See also v_k
.
let v = wlambda::VVal::map(); v.set_key_str("aaa", wlambda::VVal::new_str("XYX")); assert!(v.v_with_s_refk("aaa", |s: &str| s == "XYX"));
pub fn v_s(&self, idx: usize) -> String
[src]
Quick access of the string representation at the given idx
.
See also v_
.
let v = wlambda::VVal::vec(); v.push(wlambda::VVal::Int(13)); assert_eq!(v.v_s(0), "13");
pub fn v_sk(&self, key: &str) -> String
[src]
Quick access of the string represenation at the given key
.
See also v_k
.
let v = wlambda::VVal::map(); v.set_key_str("aaa", wlambda::VVal::Flt(12.2)); assert_eq!(v.v_sk("aaa"), "12.2");
pub fn v_f(&self, idx: usize) -> f64
[src]
Quick access of the float at the given idx
.
See also v_
.
let v = wlambda::VVal::vec(); v.push(wlambda::VVal::Flt(13.2)); assert_eq!(v.v_f(0), 13.2);
pub fn v_fk(&self, key: &str) -> f64
[src]
Quick access of the float at the given key
.
See also v_k
.
let v = wlambda::VVal::map(); v.set_key_str("aaa", wlambda::VVal::Flt(12.2)); assert_eq!(v.v_fk("aaa"), 12.2);
pub fn for_each<T>(&self, op: T) where
T: FnMut(&VVal),
[src]
T: FnMut(&VVal),
pub fn for_eachk<T>(&self, op: T) where
T: FnMut(&str, &VVal),
[src]
T: FnMut(&str, &VVal),
pub fn f(&self) -> f64
[src]
pub fn i(&self) -> i64
[src]
pub fn b(&self) -> bool
[src]
pub fn nvec<N: NVecNum>(&self) -> NVec<N>
[src]
pub fn as_bytes(&self) -> Vec<u8>
[src]
pub fn to_duration(&self) -> Result<Duration, VVal>
[src]
pub fn s(&self) -> String
[src]
Returns a string representation of the VVal data structure.
It handles cyclic data structures fine.
The purpose is to return an unambigous represenation of the data
structure. That means strings are quoted and VVal::None becomes $n
for instance.
If you need strings in pure form, use the s_raw()
method.
use wlambda::VVal; let v = VVal::None; assert_eq!(v.s(), "$n"); assert_eq!(VVal::new_str("Foo").s(), "\"Foo\"");
pub fn to_msgpack(&self) -> Result<Vec<u8>, String>
[src]
Serializes the VVal (non cyclic) structure to a msgpack byte vector.
pub fn from_msgpack(s: &[u8]) -> Result<VVal, String>
[src]
Creates a VVal structure from a msgpack byte vector.
pub fn to_json(&self, not_pretty: bool) -> Result<String, String>
[src]
Serializes the VVal (non cyclic) structure to a JSON string.
pub fn from_json(s: &str) -> Result<VVal, String>
[src]
Creates a VVal structure from a JSON string.
Trait Implementations
impl AsRef<VVal> for VVal
[src]
impl Clone for VVal
[src]
impl Debug for VVal
[src]
impl<'de> Deserialize<'de> for VVal
[src]
fn deserialize<D>(deserializer: D) -> Result<VVal, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
impl From<VVal> for StackAction
[src]
fn from(v: VVal) -> StackAction
[src]
impl PartialEq<VVal> for VVal
[src]
impl Serialize for VVal
[src]
Auto Trait Implementations
impl !RefUnwindSafe for VVal
impl !Send for VVal
impl !Sync for VVal
impl Unpin for VVal
impl !UnwindSafe for VVal
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,