pub struct Value {
pub inner: CoreValue,
pub actual_type: CoreValueType,
}Fields§
§inner: CoreValue§actual_type: CoreValueTypeImplementations§
Source§impl Value
impl Value
pub fn is_of_type(&self, target: CoreValueType) -> bool
pub fn is_null(&self) -> bool
pub fn is_text(&self) -> bool
pub fn is_i8(&self) -> bool
pub fn is_bool(&self) -> bool
Sourcepub fn try_cast_to(&self, target_type: CoreValueType) -> Option<Value>
pub fn try_cast_to(&self, target_type: CoreValueType) -> Option<Value>
Attempts to cast the value to the target type, returning an Option
§Arguments
target_type- The target type to cast the value to.
§Returns
Option<Value>- Some(Value) if the cast is successful, None if it fails.
§Example
let value = Value::from(42);
let casted_value = value.try_cast_to(CoreValueType::Text);
assert!(casted_value.is_some());
assert_eq!(casted_value.unwrap().get_type(), CoreValueType::Text);Sourcepub fn cast_to(&self, target_type: CoreValueType) -> Value
pub fn cast_to(&self, target_type: CoreValueType) -> Value
Casts the value to the target type, returning a Value. If the cast fails, it panics with an error message. This is useful for cases where you expect the cast to succeed and want to avoid handling the failure.
§Arguments
target_type- The target type to cast the value to.
§Returns
Value- The casted value.
§Panics
- If the cast fails, it panics with an error message.
§Example
let value = Value::from(42);
let casted_value = value.cast_to(CoreValueType::Text);
assert_eq!(casted_value.get_type(), CoreValueType::Text);
assert_eq!(casted_value, "42".into());Sourcepub fn cast_or_null(&self, target_type: CoreValueType) -> Value
pub fn cast_or_null(&self, target_type: CoreValueType) -> Value
Casts the value to the target type, returning a Value.
If the cast fails, it returns a Value with type Null.
This is similar to cast_to, but it returns a Value instead of an Option
§Arguments
target_type- The target type to cast the value to.
§Returns
Value- The casted value, or a Value::null() if the cast fails.
§Example
let value = Value::from(42);
let casted_value = value.cast_or_null(CoreValueType::Text);
assert_eq!(casted_value.get_type(), CoreValueType::Text);
assert_eq!(casted_value.inner.cast_to_text().0, "42".to_string());pub fn get_type(&self) -> CoreValueType
pub fn null() -> Self
Methods from Deref<Target = CoreValue>§
pub fn get_default_type(&self) -> CoreValueType
pub fn cast_to(&self, target_type: CoreValueType) -> Option<CoreValue>
pub fn cast_to_text(&self) -> Text
pub fn cast_to_bool(&self) -> Option<Boolean>
pub fn cast_to_float(&self) -> Option<TypedDecimal>
pub fn cast_to_integer(&self) -> Option<TypedInteger>
pub fn cast_to_endpoint(&self) -> Option<Endpoint>
pub fn cast_to_array(&self) -> Option<Array>
pub fn cast_to_object(&self) -> Option<Object>
pub fn cast_to_tuple(&self) -> Option<Tuple>
Trait Implementations§
Source§impl<T> AddAssign<T> for Value
impl<T> AddAssign<T> for Value
Source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
+= operation. Read moreSource§impl StructuralEq for Value
Two values are structurally equal, if their inner values are structurally equal, regardless
of the actual_type of the values
impl StructuralEq for Value
Two values are structurally equal, if their inner values are structurally equal, regardless of the actual_type of the values
Source§fn structural_eq(&self, other: &Self) -> bool
fn structural_eq(&self, other: &Self) -> bool
Source§impl ValueEq for Value
Value equality corresponds to partial equality:
Both type and inner value are the same
impl ValueEq for Value
Value equality corresponds to partial equality: Both type and inner value are the same
impl Eq for Value
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<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more