#[non_exhaustive]
pub enum Value {
Array(Vec<Value>),
Dictionary(Dictionary),
Boolean(bool),
Data(Vec<u8>),
Date(Date),
Real(f64),
Integer(Integer),
String(String),
Uid(Uid),
}
Expand description
Represents any plist value.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Array(Vec<Value>)
Dictionary(Dictionary)
Boolean(bool)
Data(Vec<u8>)
Date(Date)
Real(f64)
Integer(Integer)
String(String)
Uid(Uid)
Implementations§
source§impl Value
impl Value
sourcepub fn from_file<P: AsRef<Path>>(path: P) -> Result<Value, Error>
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Value, Error>
Reads a Value
from a plist file of any encoding.
sourcepub fn from_reader<R: Read + Seek>(reader: R) -> Result<Value, Error>
pub fn from_reader<R: Read + Seek>(reader: R) -> Result<Value, Error>
Reads a Value
from a seekable byte stream containing a plist of any encoding.
sourcepub fn from_reader_xml<R: Read>(reader: R) -> Result<Value, Error>
pub fn from_reader_xml<R: Read>(reader: R) -> Result<Value, Error>
Reads a Value
from a seekable byte stream containing an XML encoded plist.
sourcepub fn to_file_binary<P: AsRef<Path>>(&self, path: P) -> Result<(), Error>
pub fn to_file_binary<P: AsRef<Path>>(&self, path: P) -> Result<(), Error>
Serializes a Value
to a file as a binary encoded plist.
sourcepub fn to_file_xml<P: AsRef<Path>>(&self, path: P) -> Result<(), Error>
pub fn to_file_xml<P: AsRef<Path>>(&self, path: P) -> Result<(), Error>
Serializes a Value
to a file as an XML encoded plist.
sourcepub fn to_writer_binary<W: Write>(&self, writer: W) -> Result<(), Error>
pub fn to_writer_binary<W: Write>(&self, writer: W) -> Result<(), Error>
Serializes a Value
to a byte stream as a binary encoded plist.
sourcepub fn to_writer_xml<W: Write>(&self, writer: W) -> Result<(), Error>
pub fn to_writer_xml<W: Write>(&self, writer: W) -> Result<(), Error>
Serializes a Value
to a byte stream as an XML encoded plist.
sourcepub fn to_writer_xml_with_options<W: Write>(
&self,
writer: W,
options: &XmlWriteOptions
) -> Result<(), Error>
pub fn to_writer_xml_with_options<W: Write>( &self, writer: W, options: &XmlWriteOptions ) -> Result<(), Error>
Serializes a Value
to a stream, using custom XmlWriteOptions
.
If you need to serialize to a file, you must acquire an appropriate
Write
handle yourself.
Examples
use std::io::{BufWriter, Write};
use std::fs::File;
use plist::{Dictionary, Value, XmlWriteOptions};
let value: Value = Dictionary::new().into();
// .. add some keys & values
let mut file = File::create("com.example.myPlist.plist").unwrap();
let options = XmlWriteOptions::default().indent_string(" ");
value.to_writer_xml_with_options(BufWriter::new(&mut file), &options).unwrap();
file.sync_all().unwrap();
sourcepub fn into_array(self) -> Option<Vec<Value>>
pub fn into_array(self) -> Option<Vec<Value>>
If the Value
is a Array, returns the underlying Vec
.
Returns None
otherwise.
This method consumes the Value
. To get a reference instead, use
as_array
.
sourcepub fn as_array(&self) -> Option<&Vec<Value>>
pub fn as_array(&self) -> Option<&Vec<Value>>
If the Value
is an Array, returns the associated Vec
.
Returns None
otherwise.
sourcepub fn as_array_mut(&mut self) -> Option<&mut Vec<Value>>
pub fn as_array_mut(&mut self) -> Option<&mut Vec<Value>>
If the Value
is an Array, returns the associated mutable Vec
.
Returns None
otherwise.
sourcepub fn into_dictionary(self) -> Option<Dictionary>
pub fn into_dictionary(self) -> Option<Dictionary>
If the Value
is a Dictionary, returns the associated BTreeMap
.
Returns None
otherwise.
This method consumes the Value
. To get a reference instead, use
as_dictionary
.
sourcepub fn as_dictionary(&self) -> Option<&Dictionary>
pub fn as_dictionary(&self) -> Option<&Dictionary>
If the Value
is a Dictionary, returns the associated BTreeMap
.
Returns None
otherwise.
sourcepub fn as_dictionary_mut(&mut self) -> Option<&mut Dictionary>
pub fn as_dictionary_mut(&mut self) -> Option<&mut Dictionary>
If the Value
is a Dictionary, returns the associated mutable BTreeMap
.
Returns None
otherwise.
sourcepub fn as_boolean(&self) -> Option<bool>
pub fn as_boolean(&self) -> Option<bool>
If the Value
is a Boolean, returns the associated bool
.
Returns None
otherwise.
sourcepub fn into_data(self) -> Option<Vec<u8>>
pub fn into_data(self) -> Option<Vec<u8>>
If the Value
is a Data, returns the underlying Vec
.
Returns None
otherwise.
This method consumes the Value
. If this is not desired, please use
as_data
method.
sourcepub fn as_data(&self) -> Option<&[u8]>
pub fn as_data(&self) -> Option<&[u8]>
If the Value
is a Data, returns the associated Vec
.
Returns None
otherwise.
sourcepub fn as_date(&self) -> Option<Date>
pub fn as_date(&self) -> Option<Date>
If the Value
is a Date, returns the associated Date
.
Returns None
otherwise.
sourcepub fn as_real(&self) -> Option<f64>
pub fn as_real(&self) -> Option<f64>
If the Value
is a Real, returns the associated f64
.
Returns None
otherwise.
sourcepub fn as_signed_integer(&self) -> Option<i64>
pub fn as_signed_integer(&self) -> Option<i64>
If the Value
is a signed Integer, returns the associated i64
.
Returns None
otherwise.
sourcepub fn as_unsigned_integer(&self) -> Option<u64>
pub fn as_unsigned_integer(&self) -> Option<u64>
If the Value
is an unsigned Integer, returns the associated u64
.
Returns None
otherwise.
sourcepub fn into_string(self) -> Option<String>
pub fn into_string(self) -> Option<String>
If the Value
is a String, returns the underlying String
.
Returns None
otherwise.
This method consumes the Value
. If this is not desired, please use
as_string
method.
sourcepub fn as_string(&self) -> Option<&str>
pub fn as_string(&self) -> Option<&str>
If the Value
is a String, returns the associated str
.
Returns None
otherwise.