Enum wca::Value

source ·
pub enum Value {
    String(String),
    Number(f64),
    Path(PathBuf),
    Bool(bool),
    List(Vec<Value>),
}
Expand description

Container for a Value of a specific type

Uses for represent of subjects and properties in Commands( E.g. VerifiedCommand, ExecutableCommand_ ) With wca::Type enum and TryCast you can cast raw string into specific Type. You can also convert to a type that can be converted from the internal Value type.

§Example:

let command = VerifiedCommand
{
  phrase : "command".to_string(),
  // Here is numeric value used
  subjects : vec![ Value::Number( 3.14 ) ],
  properties : HashMap::from_iter(
  [
    // Here is string value used
    ( "string_prop".to_string(), Value::String( "value".to_string() ) ),
  ])
};

let number : f32 = command.subjects[ 0 ].clone().into();
assert_eq!( 3.14, number );

let number : i32 = command.subjects[ 0 ].clone().into();
assert_eq!( 3, number );

Variants§

§

String(String)

String value

§

Number(f64)

Number value(float number but can be casted to another types)

§

Path(PathBuf)

Path

§

Bool(bool)

Bool

§

List(Vec<Value>)

List

Trait Implementations§

source§

impl Clone for Value

source§

fn clone(&self) -> Value

Returns a copy 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 From<Value> for &'static str

source§

fn from(value: Value) -> Self

Converts to this type from the input type.
source§

impl From<Value> for PathBuf

source§

fn from(value: Value) -> Self

Converts to this type from the input type.
source§

impl From<Value> for String

source§

fn from(value: Value) -> Self

Converts to this type from the input type.
source§

impl<T: From<Value>> From<Value> for Vec<T>

source§

fn from(value: Value) -> Self

Converts to this type from the input type.
source§

impl From<Value> for bool

source§

fn from(value: Value) -> Self

Converts to this type from the input type.
source§

impl From<Value> for f32

source§

fn from(value: Value) -> Self

Converts to this type from the input type.
source§

impl From<Value> for f64

source§

fn from(value: Value) -> Self

Converts to this type from the input type.
source§

impl From<Value> for i32

source§

fn from(value: Value) -> Self

Converts to this type from the input type.
source§

impl From<Value> for i64

source§

fn from(value: Value) -> Self

Converts to this type from the input type.
source§

impl From<Value> for u32

source§

fn from(value: Value) -> Self

Converts to this type from the input type.
source§

impl From<Value> for u64

source§

fn from(value: Value) -> Self

Converts to this type from the input type.
source§

impl PartialEq for Value

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryCast<Value> for Type

source§

fn try_cast(&self, value: String) -> Result<Value>

return casted value
source§

impl StructuralPartialEq 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 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> 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<S> SetWithType for S

source§

fn set_with_type<T, IntoT>(&mut self, component: IntoT)
where IntoT: Into<T>, S: SetComponent<T, IntoT>,

Function to set value of a component by its type.
source§

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

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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<T> Any for T
where T: Any,

source§

impl<T> CloneAny for T
where T: Any + Clone,