Value

Struct Value 

Source
pub struct Value { /* private fields */ }
Expand description

sciter::value wrapper.

See the module-level documentation.

Implementations§

Source§

impl Value

Source

pub const fn new() -> Value

Return a new Sciter value object (undefined).

Source

pub fn array(length: usize) -> Value

Make an explicit array value with the given length.

Source

pub fn map() -> Value

Make an explicit map value.

Source

pub const fn null() -> Value

Make an explicit json null value.

Source

pub const fn nothing() -> Value

Make an explicit nothing (where did it come from?).

Source

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

Make Sciter symbol value.

Source

pub fn error(val: &str) -> Value

Make Sciter error value.

Source

pub fn color(val: u32) -> Value

Make Sciter color value, in 0xAABBGGRR form.

Source

pub fn duration(val: f64) -> Value

Make Sciter duration value, in seconds.

Source

pub fn angle(val: f64) -> Value

Make Sciter angle value, in radians.

Source

pub fn parse(val: &str) -> Result<Value, usize>

Parse a json string into value. Returns the number of chars left unparsed in case of error.

Source

pub fn parse_as(val: &str, how: VALUE_STRING_CVT_TYPE) -> Result<Value, usize>

Parse a json string into value. Returns the number of chars left unparsed in case of error.

Source

pub fn to_asset<T>(&self) -> Option<&mut IAsset<T>>

Value to asset.

Source

pub fn as_mut_ptr(&mut self) -> *mut VALUE

Returns a raw pointer to the underlaying data.

Source

pub const fn get_type(&self) -> VALUE_TYPE

Get the inner type of the value.

Source

pub const fn full_type(&self) -> (VALUE_TYPE, UINT)

Get the inner type and its subtype (e.g. units) of the value.

Source

pub fn isolate(&mut self)

Convert T_OBJECT value type to JSON T_MAP or T_ARRAY types.

Also must be used if you need to pass values between different threads.

Source

pub fn clear(&mut self) -> &mut Value

Clear the value. It deallocates all assosiated structures that are not used anywhere else.

Source

pub fn len(&self) -> usize

Return the number of items in the T_ARRAY, T_MAP, T_FUNCTION and T_OBJECT value types.

Source

pub fn push<T: Into<Value>>(&mut self, src: T)

Append another value to the end of T_ARRAY value.

Source

pub fn set<T: Into<Value>>(&mut self, index: usize, src: T)

Insert or set value at the given index of T_ARRAY, T_MAP, T_FUNCTION and T_OBJECT value.

Source

pub fn get(&self, index: usize) -> Value

Retreive value of sub-element at index.

  • T_ARRAY - nth element of the array;
  • T_MAP - value of the nth key/value pair in the map;
  • T_FUNCTION - value of the nth argument of the function.
Source

pub fn set_item<TKey: Into<Value>, TValue: Into<Value>>( &mut self, key: TKey, value: TValue, )

Insert or set value of the sub-element by key.

  • T_MAP - sets named value in the map;
  • T_OBJECT - sets value of property of the object;
  • T_FUNCTION - sets named argument of the function;
  • otherwise it converts self to the map type and adds the key/value to it.
Source

pub fn get_item<T: Into<Value>>(&self, key: T) -> Value

Retrieve the value of a sub-element by key.

Source

pub fn key_at(&self, index: usize) -> Value

Retrieve the key of a sub-element by index.

Source

pub fn keys(&self) -> KeyIterator<'_>

An iterator visiting all keys of key/value pairs in the map.

  • T_MAP - keys of key/value pairs in the map;
  • T_OBJECT - names of key/value properties in the object;
  • T_FUNCTION - names of arguments of the function (if any).

The iterator element type is Value (as a key).

Source

pub fn values(&self) -> SeqIterator<'_>

An iterator visiting all values in arbitrary order.

  • T_ARRAY - elements of the array;
  • T_MAP - values of key/value pairs in the map;
  • T_OBJECT - values of key/value properties in the object;
  • T_FUNCTION - values of arguments of the function.

The iterator element type is Value.

Source

pub fn items(&self) -> Vec<(Value, Value)>

An iterator visiting all key-value pairs in arbitrary order.

The Value must has a key-value type (map, object, function).

The iterator element type is (Value, Value).

Source

pub fn to_int(&self) -> Option<i32>

Value to integer.

Source

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

Value to bool.

Source

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

Value to float.

Source

pub fn to_color(&self) -> Option<u32>

Value to color.

Source

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

Value to duration.

Source

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

Value to angle.

Source

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

Value as string for T_STRING type.

Source

pub fn into_string(self) -> String

Value to json string (converted in-place). Subject to change.

Source

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

Value as a byte slice for T_BYTES type.

Source

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

Value to byte vector for T_BYTES type.

Source

pub fn call( &self, this: Option<Value>, args: &[Value], name: Option<&str>, ) -> Result<Value, VALUE_RESULT>

Function invocation for T_OBJECT with UT_OBJECT_FUNCTION value type.

Calls the tiscript function or method holded at Value with context of this object that will be known as this inside that function (it is optional for global functions).

The name here is an url or a name of the script - used for error reporting in script.

You can use the make_args!(args...) macro which helps you to construct script arguments from Rust types.

Source

pub fn is_empty(&self) -> bool

Returns true is self is undefined or has zero elements.

Source

pub const fn is_undefined(&self) -> bool

Source

pub const fn is_null(&self) -> bool

Source

pub const fn is_nothing(&self) -> bool

Source

pub const fn is_bool(&self) -> bool

Source

pub const fn is_int(&self) -> bool

Source

pub const fn is_float(&self) -> bool

Source

pub const fn is_bytes(&self) -> bool

Source

pub const fn is_string(&self) -> bool

Source

pub const fn is_symbol(&self) -> bool

Source

pub const fn is_error_string(&self) -> bool

Source

pub const fn is_date(&self) -> bool

Source

pub const fn is_currency(&self) -> bool

Source

pub const fn is_color(&self) -> bool

Source

pub const fn is_duration(&self) -> bool

Source

pub const fn is_angle(&self) -> bool

Source

pub const fn is_map(&self) -> bool

Source

pub const fn is_array(&self) -> bool

Source

pub const fn is_function(&self) -> bool

Source

pub fn is_native_function(&self) -> bool

Source

pub const fn is_object(&self) -> bool

Source

pub const fn is_asset(&self) -> bool

Source

pub const fn is_primitive(&self) -> bool

I.e. non-reference types that do not need a destructor.

Source

pub const fn is_object_array(&self) -> bool

Source

pub const fn is_object_map(&self) -> bool

Source

pub const fn is_object_class(&self) -> bool

Source

pub const fn is_object_native(&self) -> bool

Source

pub const fn is_object_function(&self) -> bool

Source

pub const fn is_object_error(&self) -> bool

Source

pub const fn is_dom_element(&self) -> bool

Source

pub const fn is_varray(&self) -> bool

Source

pub const fn is_vmap(&self) -> bool

Source

pub fn is_vfunction(&self) -> bool

Source

pub const fn is_verror(&self) -> bool

Trait Implementations§

Source§

impl Clone for Value

Copies value.

All allocated objects are reference counted so copying is just a matter of increasing reference counts.

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

Print Value as json string with explicit type showed.

Source§

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

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

impl Default for Value

Return default value (undefined).

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Value

Print Value as json string

Source§

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

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

impl Drop for Value

Destroy pointed value.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a> From<&'a [u8]> for Value

Value from binary array (sequence of bytes).

Source§

fn from(val: &'a [u8]) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a String> for Value

Source§

fn from(val: &'a String) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a VALUE> for Value

Value from a native VALUE object.

Source§

fn from(val: &'a VALUE) -> Self

Converts to this type from the input type.
Source§

impl From<&bool> for Value

Value from bool.

Source§

fn from(val: &bool) -> Self

Converts to this type from the input type.
Source§

impl From<&f64> for Value

Value from float.

Source§

fn from(val: &f64) -> Self

Converts to this type from the input type.
Source§

impl From<&i32> for Value

Value from integer.

Source§

fn from(val: &i32) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a str> for Value

Value from string.

Source§

fn from(val: &'a str) -> Self

Converts to this type from the input type.
Source§

impl From<()> for Value

Value from nothing (()) for empty return values.

Returns undefined value.

Source§

fn from(_: ()) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Box<IAsset<T>>> for Value

Value from asset.

Source§

fn from(ptr: Box<IAsset<T>>) -> Value

Converts to this type from the input type.
Source§

impl<F, R> From<F> for Value
where F: Fn(&[Value]) -> R, R: Into<Value>,

Value from function.

Source§

fn from(f: F) -> Value

Converts to this type from the input type.
Source§

impl From<Graphics> for Value

Store the Graphics object as a Value.

Source§

fn from(i: Graphics) -> Value

Converts to this type from the input type.
Source§

impl From<Image> for Value

Store the Image object as a Value.

Source§

fn from(i: Image) -> Value

Converts to this type from the input type.
Source§

impl From<Path> for Value

Store the Path object as a Value.

Source§

fn from(i: Path) -> Value

Converts to this type from the input type.
Source§

impl<T, E> From<Result<T, E>> for Value
where T: Into<Value>, E: Display,

Value from Result.

Source§

fn from(val: Result<T, E>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Value from string.

Source§

fn from(val: String) -> Self

Converts to this type from the input type.
Source§

impl From<SystemTime> for Value

Value from time/date.

Source§

fn from(val: SystemTime) -> Self

See the [VALUE_TIME::T_DATE].

Source§

impl From<Text> for Value

Store the Text object as a Value.

Source§

fn from(i: Text) -> Value

Converts to this type from the input type.
Source§

impl From<bool> for Value

Value from bool.

Source§

fn from(val: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Value from float.

Source§

fn from(val: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Value from integer.

Source§

fn from(val: i32) -> Self

Converts to this type from the input type.
Source§

impl<'a> FromIterator<&'a str> for Value

Value from sequence of &str.

Source§

fn from_iter<I: IntoIterator<Item = &'a str>>(iterator: I) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<String> for Value

Value from sequence of String.

Source§

fn from_iter<I: IntoIterator<Item = String>>(iterator: I) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<Value> for Value

Value from sequence of Value.

Source§

fn from_iter<I: IntoIterator<Item = Value>>(iterator: I) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<f64> for Value

Value from sequence of f64.

Source§

fn from_iter<I: IntoIterator<Item = f64>>(iterator: I) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<i32> for Value

Value from sequence of i32.

Source§

fn from_iter<I: IntoIterator<Item = i32>>(iterator: I) -> Self

Creates a value from an iterator. Read more
Source§

impl FromStr for Value

Value from json string.

Source§

type Err = VALUE_RESULT

The associated error which can be returned from parsing.
Source§

fn from_str(val: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl FromValue for Value

Source§

fn from_value(v: &Value) -> Option<Self>

Converts value to specified type.
Source§

impl Index<&'static str> for Value

Get item by string key for map type.

Source§

type Output = Value

The returned type after indexing.
Source§

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

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

impl Index<Value> for Value

Get item by key for map type.

Source§

type Output = Value

The returned type after indexing.
Source§

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

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

impl Index<usize> for Value

Get item by index for array type.

Source§

type Output = Value

The returned type after indexing.
Source§

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

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

impl<'a> IntoIterator for &'a Value

Conversion into an Iterator.

Adds the for loop syntax support: for subitem in &value {].

Source§

type Item = Value

The type of the elements being iterated over.
Source§

type IntoIter = SeqIterator<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Value

Compare two values.

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 TryFrom<Element> for Value

Store the DOM element as a Value.

Since 4.4.3.26, perhaps.

Source§

type Error = SCDOM_RESULT

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

fn try_from(e: Element) -> Result<Value>

Performs the conversion.
Source§

impl Send for Value

sciter::Value can be transferred across thread boundaries.

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl !Sync for Value

§

impl Unpin 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<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.