Trait value_trait::ValueAccess
source · pub trait ValueAccess: Sized {
type Target: ValueAccess;
type Key: Hash + Eq;
type Array: Array<Element = Self::Target>;
type Object: Object<Key = Self::Key, Element = Self::Target>;
Show 39 methods
// Required methods
fn as_bool(&self) -> Option<bool>;
fn as_i64(&self) -> Option<i64>;
fn as_u64(&self) -> Option<u64>;
fn as_f64(&self) -> Option<f64>;
fn as_str(&self) -> Option<&str>;
fn as_array(&self) -> Option<&Self::Array>;
fn as_object(&self) -> Option<&Self::Object>;
// Provided methods
fn get<Q>(&self, k: &Q) -> Option<&Self::Target>
where Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized { ... }
fn contains_key<Q>(&self, k: &Q) -> bool
where Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized { ... }
fn get_idx(&self, i: usize) -> Option<&Self::Target> { ... }
fn get_bool<Q>(&self, k: &Q) -> Option<bool>
where Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized { ... }
fn as_i128(&self) -> Option<i128> { ... }
fn get_i128<Q>(&self, k: &Q) -> Option<i128>
where Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized { ... }
fn get_i64<Q>(&self, k: &Q) -> Option<i64>
where Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized { ... }
fn as_i32(&self) -> Option<i32> { ... }
fn get_i32<Q>(&self, k: &Q) -> Option<i32>
where Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized { ... }
fn as_i16(&self) -> Option<i16> { ... }
fn get_i16<Q>(&self, k: &Q) -> Option<i16>
where Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized { ... }
fn as_i8(&self) -> Option<i8> { ... }
fn get_i8<Q>(&self, k: &Q) -> Option<i8>
where Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized { ... }
fn as_u128(&self) -> Option<u128> { ... }
fn get_u128<Q>(&self, k: &Q) -> Option<u128>
where Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized { ... }
fn get_u64<Q>(&self, k: &Q) -> Option<u64>
where Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized { ... }
fn as_usize(&self) -> Option<usize> { ... }
fn get_usize<Q>(&self, k: &Q) -> Option<usize>
where Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized { ... }
fn as_u32(&self) -> Option<u32> { ... }
fn get_u32<Q>(&self, k: &Q) -> Option<u32>
where Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized { ... }
fn as_u16(&self) -> Option<u16> { ... }
fn get_u16<Q>(&self, k: &Q) -> Option<u16>
where Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized { ... }
fn as_u8(&self) -> Option<u8> { ... }
fn get_u8<Q>(&self, k: &Q) -> Option<u8>
where Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized { ... }
fn get_f64<Q>(&self, k: &Q) -> Option<f64>
where Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized { ... }
fn cast_f64(&self) -> Option<f64> { ... }
fn as_f32(&self) -> Option<f32> { ... }
fn get_f32<Q>(&self, k: &Q) -> Option<f32>
where Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized { ... }
fn as_char(&self) -> Option<char> { ... }
fn get_str<Q>(&self, k: &Q) -> Option<&str>
where Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized { ... }
fn get_array<Q>(
&self,
k: &Q,
) -> Option<&<<Self as ValueAccess>::Target as ValueAccess>::Array>
where Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized { ... }
fn get_object<Q>(
&self,
k: &Q,
) -> Option<&<<Self as ValueAccess>::Target as ValueAccess>::Object>
where Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized { ... }
}
Expand description
Trait to allow accessing data inside a Value
Required Associated Types§
sourcetype Target: ValueAccess
type Target: ValueAccess
The target for nested lookups
Required Methods§
Provided Methods§
sourcefn get<Q>(&self, k: &Q) -> Option<&Self::Target>
fn get<Q>(&self, k: &Q) -> Option<&Self::Target>
Gets a ref to a value based on a key, returns None
if the
current Value isn’t an Object or doesn’t contain the key
it was asked for.
sourcefn contains_key<Q>(&self, k: &Q) -> bool
fn contains_key<Q>(&self, k: &Q) -> bool
Checks if a Value contains a given key. This will return flase if Value isn’t an object
sourcefn get_idx(&self, i: usize) -> Option<&Self::Target>
fn get_idx(&self, i: usize) -> Option<&Self::Target>
Gets a ref to a value based on n index, returns None
if the
current Value isn’t an Array or doesn’t contain the index
it was asked for.
sourcefn cast_f64(&self) -> Option<f64>
fn cast_f64(&self) -> Option<f64>
Casts the current value to a f64 if possible, this will turn integer values into floats.
sourcefn get_array<Q>(
&self,
k: &Q,
) -> Option<&<<Self as ValueAccess>::Target as ValueAccess>::Array>
fn get_array<Q>( &self, k: &Q, ) -> Option<&<<Self as ValueAccess>::Target as ValueAccess>::Array>
Tries to get an element of an object as a array
Object Safety§
This trait is not object safe.