Skip to main content

Value

Enum Value 

Source
#[non_exhaustive]
pub enum Value { Dictionary(Dictionary), Array(Vec<Self>), String(String), Integer(Integer), Real(Real), Boolean(bool), Uid(Uid), Data(Vec<u8>), Date(Date), }
Expand description

Any value a property list can hold.

The tree is owned (String / Vec / Dictionary, no lifetimes) and covers the nine property-list value kinds. Dictionaries preserve key insertion order.

The enum is #[non_exhaustive]; equality is PartialEq only, because a real may hold NaN.

§Examples

use apple_plist::Value;

let value = Value::from_iter([
    ("name".to_owned(), Value::from("plist")),
    ("count".to_owned(), Value::from(3u8)),
]);
let dict = value.as_dictionary().expect("built a dictionary");
assert_eq!(dict.get("name").and_then(Value::as_str), Some("plist"));

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Dictionary(Dictionary)

A dictionary; keys preserve insertion order.

§

Array(Vec<Self>)

An ordered array.

§

String(String)

A UTF-8 string.

§

Integer(Integer)

An integer, signed or unsigned.

§

Real(Real)

A floating-point number.

§

Boolean(bool)

A boolean.

§

Uid(Uid)

A keyed-archive CF$UID reference.

§

Data(Vec<u8>)

Raw bytes.

§

Date(Date)

An absolute point in time.

Implementations§

Source§

impl Value

Source

pub const fn as_dictionary(&self) -> Option<&Dictionary>

Returns the dictionary behind Value::Dictionary.

§Examples
use apple_plist::{Dictionary, Value};

let value = Value::from(Dictionary::new());
assert!(value.as_dictionary().is_some());
assert!(Value::from(true).as_dictionary().is_none());
Source

pub const fn as_dictionary_mut(&mut self) -> Option<&mut Dictionary>

Returns the dictionary behind Value::Dictionary, mutably.

§Examples
use apple_plist::{Dictionary, Value};

let mut value = Value::from(Dictionary::new());
if let Some(dict) = value.as_dictionary_mut() {
    let _ = dict.insert("key".to_owned(), Value::from(1u8));
}
assert_eq!(value.as_dictionary().map(Dictionary::len), Some(1));
Source

pub const fn as_array(&self) -> Option<&Vec<Self>>

Returns the elements behind Value::Array.

§Examples
use apple_plist::Value;

let value = Value::from(vec![Value::from(true)]);
assert_eq!(value.as_array().map(Vec::len), Some(1));
assert!(Value::from(true).as_array().is_none());
Source

pub const fn as_array_mut(&mut self) -> Option<&mut Vec<Self>>

Returns the elements behind Value::Array, mutably.

§Examples
use apple_plist::Value;

let mut value = Value::from(Vec::<Value>::new());
if let Some(values) = value.as_array_mut() {
    values.push(Value::from(7i32));
}
assert_eq!(value.as_array().map(Vec::len), Some(1));
Source

pub const fn as_str(&self) -> Option<&str>

Returns the string slice behind Value::String.

§Examples
use apple_plist::Value;

assert_eq!(Value::from("hello").as_str(), Some("hello"));
assert_eq!(Value::from(false).as_str(), None);
Source

pub const fn as_integer(&self) -> Option<Integer>

Returns the integer behind Value::Integer.

§Examples
use apple_plist::{Integer, Value};

assert_eq!(Value::from(-1i64).as_integer(), Some(Integer::Signed(-1)));
assert_eq!(Value::from("1").as_integer(), None);
Source

pub const fn as_real(&self) -> Option<f64>

Returns the numeric value behind Value::Real as an f64.

§Examples
use apple_plist::Value;

assert_eq!(Value::from(1.5).as_real(), Some(1.5));
assert_eq!(Value::from(1u8).as_real(), None);
Source

pub const fn as_boolean(&self) -> Option<bool>

Returns the boolean behind Value::Boolean.

§Examples
use apple_plist::Value;

assert_eq!(Value::from(true).as_boolean(), Some(true));
assert_eq!(Value::from("true").as_boolean(), None);
Source

pub const fn as_data(&self) -> Option<&[u8]>

Returns the bytes behind Value::Data.

§Examples
use apple_plist::Value;

assert_eq!(Value::from(vec![1u8, 2]).as_data(), Some(&[1u8, 2][..]));
assert_eq!(Value::from("12").as_data(), None);
Source

pub const fn as_date(&self) -> Option<Date>

Returns the date behind Value::Date.

§Examples
use std::time::SystemTime;

use apple_plist::{Date, Value};

let date = Date::from(SystemTime::UNIX_EPOCH);
assert_eq!(Value::from(date).as_date(), Some(date));
assert_eq!(Value::from(0i64).as_date(), None);
Source

pub const fn as_uid(&self) -> Option<Uid>

Returns the UID behind Value::Uid.

§Examples
use apple_plist::{Uid, Value};

assert_eq!(Value::from(Uid::from(7)).as_uid(), Some(Uid::from(7)));
assert_eq!(Value::from(7u64).as_uid(), None);
Source

pub fn into_dictionary(self) -> Option<Dictionary>

Consumes the value, returning the dictionary behind Value::Dictionary.

§Examples
use apple_plist::{Dictionary, Value};

assert_eq!(
    Value::from(Dictionary::new()).into_dictionary(),
    Some(Dictionary::new())
);
assert_eq!(Value::from(true).into_dictionary(), None);
Source

pub fn into_array(self) -> Option<Vec<Self>>

Consumes the value, returning the elements behind Value::Array.

§Examples
use apple_plist::Value;

assert_eq!(
    Value::from(vec![Value::from(1u8)]).into_array(),
    Some(vec![Value::from(1u8)])
);
assert_eq!(Value::from(1u8).into_array(), None);
Source

pub fn into_string(self) -> Option<String>

Consumes the value, returning the string behind Value::String.

§Examples
use apple_plist::Value;

assert_eq!(Value::from("hi").into_string(), Some("hi".to_owned()));
assert_eq!(Value::from(true).into_string(), None);
Source

pub fn into_data(self) -> Option<Vec<u8>>

Consumes the value, returning the bytes behind Value::Data.

§Examples
use apple_plist::Value;

assert_eq!(Value::from(vec![1u8, 2]).into_data(), Some(vec![1u8, 2]));
assert_eq!(Value::from("12").into_data(), None);

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Value

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&str> for Value

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Date> for Value

Source§

fn from(value: Date) -> Self

Converts to this type from the input type.
Source§

impl From<IndexMap<String, Value>> for Value

Source§

fn from(value: Dictionary) -> Self

Converts to this type from the input type.
Source§

impl From<Integer> for Value

Source§

fn from(value: Integer) -> Self

Converts to this type from the input type.
Source§

impl From<Real> for Value

Source§

fn from(value: Real) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<Uid> for Value

Source§

fn from(value: Uid) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Value>> for Value

Source§

fn from(value: Vec<Self>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Value

The []byte → cfData rule at the literal level: a byte vector is data, never an array. Element-wise arrays go through FromIterator.

Source§

fn from(value: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Value

Source§

fn from(value: i8) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Value

Source§

fn from(value: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Value

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Value

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Value

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<(String, Value)> for Value

Builds a dictionary in iteration order; the last value wins for duplicate keys, and the key keeps its first position.

Source§

fn from_iter<T: IntoIterator<Item = (String, Self)>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<Value> for Value

Source§

fn from_iter<T: IntoIterator<Item = Self>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Value) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Value

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

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 UnsafeUnpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.