#[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
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
impl Value
Sourcepub const fn as_dictionary(&self) -> Option<&Dictionary>
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());Sourcepub const fn as_dictionary_mut(&mut self) -> Option<&mut Dictionary>
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));Sourcepub const fn as_array(&self) -> Option<&Vec<Self>>
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());Sourcepub const fn as_array_mut(&mut self) -> Option<&mut Vec<Self>>
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));Sourcepub const fn as_str(&self) -> Option<&str>
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);Sourcepub const fn as_integer(&self) -> Option<Integer>
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);Sourcepub const fn as_real(&self) -> Option<f64>
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);Sourcepub const fn as_boolean(&self) -> Option<bool>
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);Sourcepub const fn as_data(&self) -> Option<&[u8]>
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);Sourcepub const fn as_date(&self) -> Option<Date>
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);Sourcepub const fn as_uid(&self) -> Option<Uid>
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);Sourcepub fn into_dictionary(self) -> Option<Dictionary>
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);Sourcepub fn into_array(self) -> Option<Vec<Self>>
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);Sourcepub fn into_string(self) -> Option<String>
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);Trait Implementations§
Source§impl<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl From<IndexMap<String, Value>> for Value
impl From<IndexMap<String, Value>> for Value
Source§fn from(value: Dictionary) -> Self
fn from(value: Dictionary) -> Self
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.
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§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.
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.