pub enum Value {
    Bool(bool),
    String(String),
    Float(f64),
    Integer(i64),
    Data(Vec<u8>),
}
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

A handy initializer for Value::String.

Returns true if the value is a boolean value. Returns false otherwise.

If this is a Bool, it returns the associated bool. Returns None otherwise.

Returns true if the value is a string. Returns false otherwise.

If this is a String, it returns a &str. Returns None otherwise.

Returns true if the value is a float. Returns false otherwise.

If this is a int, returns it (i32). Returns None otherwise.

If this is a int, returns it (i64). Returns None otherwise.

Returns true if the value is a float. Returns false otherwise.

If this is a float, returns it (f32). Returns None otherwise.

If this is a float, returns it (f64). Returns None otherwise.

Returns true if the value is data. Returns false otherwise.

If this is data, returns it (&[u8]). If you need to own the underlying buffer, you can extract it yourself. Returns None if this is not Data.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Shepherds Value types into NSObjects that can be stored in NSUserDefaults.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.