Expand description
Represents a Value that can be stored or queried with UserDefaults
.
In general, this wraps a few types that should hopefully work for most cases. Note that the
Value
always owns whatever it holds - this is both for ergonomic considerations, as
well as contractual obligations with the underlying NSUserDefaults
system.
Variants
Bool(bool)
Represents a Boolean value.
String(String)
Represents a String value.
Float(f64)
Represents a Float (f64
) value.
Integer(i64)
Represents an Integer (i64
) value.
Data(Vec<u8>)
Represents Data (bytes). You can use this to store arbitrary things that aren’t supported above. You’re responsible for moving things back and forth to the necessary types.
Implementations
sourceimpl Value
impl Value
sourcepub fn is_boolean(&self) -> bool
pub fn is_boolean(&self) -> bool
Returns true
if the value is a boolean value. Returns false
otherwise.
sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
If this is a Bool, it returns the associated bool. Returns None
otherwise.
sourcepub fn is_string(&self) -> bool
pub fn is_string(&self) -> bool
Returns true
if the value is a string. Returns false
otherwise.
sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
If this is a String, it returns a &str. Returns None
otherwise.
sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Returns true
if the value is a float. Returns false
otherwise.
sourcepub fn as_i32(&self) -> Option<i32>
pub fn as_i32(&self) -> Option<i32>
If this is a int, returns it (i32
). Returns None
otherwise.
sourcepub fn as_i64(&self) -> Option<i64>
pub fn as_i64(&self) -> Option<i64>
If this is a int, returns it (i64
). Returns None
otherwise.
sourcepub fn as_f32(&self) -> Option<f32>
pub fn as_f32(&self) -> Option<f32>
If this is a float, returns it (f32
). Returns None
otherwise.
Trait Implementations
impl StructuralPartialEq for Value
Auto Trait Implementations
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnwindSafe for Value
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more