pub enum KvValue {
Float(f64),
Int(i64),
Uint(u64),
Bool(bool),
Str(String),
}Expand description
Types available for use in KV.
Float, Int and Uint are all 64bit. The corresponding 32bit variants must be
be converted to 64 bit. Preferably the From impls are used to create a KvValue:
let x: KvValue = 1u64.into();
assert_eq!(x, KvValue::Uint(1u64));
let x: KvValue = 2u32.into();
assert_eq!(x, KvValue::Uint(2u64));
let x: KvValue = 2i64.into();
assert_eq!(x, KvValue::Int(2i64));
let x: KvValue = 2i32.into();
assert_eq!(x, KvValue::Int(2i64));
let x: KvValue = 1.0f64.into();
assert_eq!(x, KvValue::Float(1f64));
let x: KvValue = 1.0f32.into();
assert_eq!(x, KvValue::Float(1f64));
let x: KvValue = true.into();
assert_eq!(x, KvValue::Bool(true));
let x: KvValue = "a str".into();
assert_eq!(x, KvValue::Str("a str".to_string()));
let x: KvValue = "a String".to_string().into();
assert_eq!(x, KvValue::Str("a String".to_string()));Variants§
Float(f64)
Floating point values
Int(i64)
Signed integers
Uint(u64)
Unsigned integers
Bool(bool)
Boolean values
Str(String)
Strings
Implementations§
Source§impl KvValue
impl KvValue
Sourcepub fn kind(&self) -> &'static str
pub fn kind(&self) -> &'static str
Returns the kind of the KvValue
§Examples
assert_eq!(KvValue::Float(1.0).kind(), "Float");
assert_eq!(KvValue::Int(1).kind(), "Int");
assert_eq!(KvValue::Uint(1).kind(), "Uint");
assert_eq!(KvValue::Bool(true).kind(), "Bool");
assert_eq!(KvValue::Str("string".to_string()).kind(), "Str");Sourcepub fn get_float(&self) -> Option<f64>
pub fn get_float(&self) -> Option<f64>
Extract float from KvValue
Returns Some(<float>) if KvValue is of kind Float.
Note: For KvValue::Int and KvValue::Uintinteger values are cast to f64, therefore
this operation may be lossy!
KvValue::Bool is turned into 1.0f64 if true and 0.0f64 if false.
§Example
assert_eq!(KvValue::Float(1.0).get_float(), Some(1.0));
assert_eq!(KvValue::Int(1).get_float(), Some(1.0));
assert_eq!(KvValue::Uint(1).get_float(), Some(1.0));
assert_eq!(KvValue::Bool(true).get_float(), Some(1.0));
assert_eq!(KvValue::Str("not a number".to_string()).get_float(), None);Sourcepub fn get_int(&self) -> Option<i64>
pub fn get_int(&self) -> Option<i64>
Extract int from KvValue
Returns Some(<int>) if KvValue is of kind Int and None otherwise.
§Example
assert_eq!(KvValue::Int(1).get_int(), Some(1i64));
assert_eq!(KvValue::Float(1.0).get_int(), None);
assert_eq!(KvValue::Uint(1).get_int(), None);
assert_eq!(KvValue::Bool(true).get_int(), None);
assert_eq!(KvValue::Str("not an int".to_string()).get_int(), None);Sourcepub fn get_uint(&self) -> Option<u64>
pub fn get_uint(&self) -> Option<u64>
Extract unsigned int from KvValue
Returns Some(<unsigned int>) if KvValue is of kind Uint and None otherwise.
§Example
assert_eq!(KvValue::Uint(1).get_uint(), Some(1u64));
assert_eq!(KvValue::Int(1).get_uint(), None);
assert_eq!(KvValue::Float(1.0).get_uint(), None);
assert_eq!(KvValue::Bool(true).get_uint(), None);
assert_eq!(KvValue::Str("not an uint".to_string()).get_uint(), None);Sourcepub fn get_bool(&self) -> Option<bool>
pub fn get_bool(&self) -> Option<bool>
Extract bool from KvValue
Returns Some(<bool>) if KvValue is of kind Bool and None otherwise.
§Example
assert_eq!(KvValue::Bool(true).get_bool(), Some(true));
assert_eq!(KvValue::Float(1.0).get_bool(), None);
assert_eq!(KvValue::Int(1).get_bool(), None);
assert_eq!(KvValue::Uint(1).get_bool(), None);
assert_eq!(KvValue::Str("not a bool".to_string()).get_bool(), None);Sourcepub fn get_string(&self) -> Option<String>
pub fn get_string(&self) -> Option<String>
Extract String from KvValue
Returns Some(<string>) if KvValue is of kind Str and None otherwise.
§Example
assert_eq!(KvValue::Str("a string".to_string()).get_string(), Some("a string".to_string()));
assert_eq!(KvValue::Float(1.0).get_string(), None);
assert_eq!(KvValue::Int(1).get_string(), None);
assert_eq!(KvValue::Uint(1).get_string(), None);
assert_eq!(KvValue::Bool(true).get_string(), None);Sourcepub fn as_string(&self) -> String
pub fn as_string(&self) -> String
Get String representation of KvValue
§Example
assert_eq!(KvValue::Str("a string".to_string()).as_string(), "a string".to_string());
assert_eq!(KvValue::Float(1.0).as_string(), "1".to_string());
assert_eq!(KvValue::Int(1).as_string(), "1".to_string());
assert_eq!(KvValue::Uint(1).as_string(), "1".to_string());
assert_eq!(KvValue::Bool(true).as_string(), "true".to_string());Trait Implementations§
Source§impl<'de> Deserialize<'de> for KvValue
impl<'de> Deserialize<'de> for KvValue
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<KvValue, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<KvValue, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for KvValue
impl Serialize for KvValue
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for KvValue
Auto Trait Implementations§
impl Freeze for KvValue
impl RefUnwindSafe for KvValue
impl Send for KvValue
impl Sync for KvValue
impl Unpin for KvValue
impl UnwindSafe for KvValue
Blanket Implementations§
Source§impl<T> AlignerFor<1> for T
impl<T> AlignerFor<1> for T
Source§impl<T> AlignerFor<1024> for T
impl<T> AlignerFor<1024> for T
Source§type Aligner = AlignTo1024<T>
type Aligner = AlignTo1024<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<128> for T
impl<T> AlignerFor<128> for T
Source§type Aligner = AlignTo128<T>
type Aligner = AlignTo128<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<16> for T
impl<T> AlignerFor<16> for T
Source§impl<T> AlignerFor<16384> for T
impl<T> AlignerFor<16384> for T
Source§type Aligner = AlignTo16384<T>
type Aligner = AlignTo16384<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<2> for T
impl<T> AlignerFor<2> for T
Source§impl<T> AlignerFor<2048> for T
impl<T> AlignerFor<2048> for T
Source§type Aligner = AlignTo2048<T>
type Aligner = AlignTo2048<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<256> for T
impl<T> AlignerFor<256> for T
Source§type Aligner = AlignTo256<T>
type Aligner = AlignTo256<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<32> for T
impl<T> AlignerFor<32> for T
Source§impl<T> AlignerFor<32768> for T
impl<T> AlignerFor<32768> for T
Source§type Aligner = AlignTo32768<T>
type Aligner = AlignTo32768<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<4> for T
impl<T> AlignerFor<4> for T
Source§impl<T> AlignerFor<4096> for T
impl<T> AlignerFor<4096> for T
Source§type Aligner = AlignTo4096<T>
type Aligner = AlignTo4096<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<512> for T
impl<T> AlignerFor<512> for T
Source§type Aligner = AlignTo512<T>
type Aligner = AlignTo512<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<64> for T
impl<T> AlignerFor<64> for T
Source§impl<T> AlignerFor<8> for T
impl<T> AlignerFor<8> for T
Source§impl<T> AlignerFor<8192> for T
impl<T> AlignerFor<8192> for T
Source§type Aligner = AlignTo8192<T>
type Aligner = AlignTo8192<T>
AlignTo* type which aligns Self to ALIGNMENT.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<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<'a, T> RCowCompatibleRef<'a> for Twhere
T: Clone + 'a,
impl<'a, T> RCowCompatibleRef<'a> for Twhere
T: Clone + 'a,
Source§fn as_c_ref(from: &'a T) -> <T as RCowCompatibleRef<'a>>::RefC
fn as_c_ref(from: &'a T) -> <T as RCowCompatibleRef<'a>>::RefC
Source§fn as_rust_ref(from: <T as RCowCompatibleRef<'a>>::RefC) -> &'a T
fn as_rust_ref(from: <T as RCowCompatibleRef<'a>>::RefC) -> &'a T
Source§impl<S> ROExtAcc for S
impl<S> ROExtAcc for S
Source§fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
offset. Read moreSource§fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
offset. Read moreSource§fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
offset. Read moreSource§fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
offset. Read moreSource§impl<S> ROExtOps<Aligned> for S
impl<S> ROExtOps<Aligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
offset) with value,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
Source§impl<S> ROExtOps<Unaligned> for S
impl<S> ROExtOps<Unaligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
offset) with value,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
Source§impl<T> SelfOps for Twhere
T: ?Sized,
impl<T> SelfOps for Twhere
T: ?Sized,
Source§fn piped<F, U>(self, f: F) -> U
fn piped<F, U>(self, f: F) -> U
Source§fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
piped except that the function takes &Self
Useful for functions that take &Self instead of Self. Read moreSource§fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
piped, except that the function takes &mut Self.
Useful for functions that take &mut Self instead of Self.Source§fn mutated<F>(self, f: F) -> Self
fn mutated<F>(self, f: F) -> Self
Source§fn observe<F>(self, f: F) -> Self
fn observe<F>(self, f: F) -> Self
Source§fn as_ref_<T>(&self) -> &T
fn as_ref_<T>(&self) -> &T
AsRef,
using the turbofish .as_ref_::<_>() syntax. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.