plist/lib.rs
1//! # Plist
2//!
3//! A rusty plist parser.
4//!
5//! ## Usage
6//!
7//! Put this in your `Cargo.toml`:
8//!
9//! ```toml
10//! [dependencies]
11//! plist = "1"
12//! ```
13//!
14//! And put this in your crate root:
15//!
16//! ```rust
17//! extern crate plist;
18//! ```
19//!
20//! ## Examples
21//!
22//! ### Using `serde`
23//!
24//! ```rust
25//! extern crate plist;
26//! # #[cfg(feature = "serde")]
27//! #[macro_use]
28//! extern crate serde_derive;
29//!
30//! # #[cfg(feature = "serde")]
31//! # fn main() {
32//! #[derive(Deserialize)]
33//! #[serde(rename_all = "PascalCase")]
34//! struct Book {
35//! title: String,
36//! author: String,
37//! excerpt: String,
38//! copies_sold: u64,
39//! }
40//!
41//! let book: Book = plist::from_file("tests/data/book.plist")
42//! .expect("failed to read book.plist");
43//!
44//! assert_eq!(book.title, "Great Expectations");
45//! # }
46//! #
47//! # #[cfg(not(feature = "serde"))]
48//! # fn main() {}
49//! ```
50//!
51//! ### Using `Value`
52//!
53//! ```rust
54//! use plist::Value;
55//!
56//! let book = Value::from_file("tests/data/book.plist")
57//! .expect("failed to read book.plist");
58//!
59//! let title = book
60//! .as_dictionary()
61//! .and_then(|dict| dict.get("Title"))
62//! .and_then(|title| title.as_string());
63//!
64//! assert_eq!(title, Some("Great Expectations"));
65//! ```
66//!
67//! ## Unstable Features
68//!
69//! Many features from previous versions are now hidden behind the
70//! `enable_unstable_features_that_may_break_with_minor_version_bumps` feature. These will break in
71//! minor version releases after the 1.0 release. If you really really must use them you should
72//! specify a tilde requirement e.g. `plist = "~1.0.3"` in you `Cargo.toml` so that the plist crate
73//! is not automatically updated to version 1.1.
74
75#![deny(warnings)] // Treat all warnings as errors
76#![deny(rustdoc::broken_intra_doc_links)]
77
78pub mod dictionary;
79
80#[cfg(feature = "enable_unstable_features_that_may_break_with_minor_version_bumps")]
81pub mod stream;
82#[cfg(not(feature = "enable_unstable_features_that_may_break_with_minor_version_bumps"))]
83mod stream;
84
85#[cfg(feature = "serde")]
86mod data;
87mod date;
88mod error;
89mod integer;
90mod uid;
91mod value;
92
93#[cfg(feature = "serde")]
94pub use data::Data;
95pub use date::{Date, InvalidXmlDate};
96pub use dictionary::Dictionary;
97pub use error::Error;
98pub use integer::Integer;
99pub use stream::XmlWriteOptions;
100pub use uid::Uid;
101pub use value::Value;
102
103// Optional serde module
104#[cfg(feature = "serde")]
105#[macro_use]
106extern crate serde;
107#[cfg(feature = "serde")]
108mod de;
109#[cfg(feature = "serde")]
110mod ser;
111#[cfg(all(
112 feature = "serde",
113 any(
114 test,
115 feature = "enable_unstable_features_that_may_break_with_minor_version_bumps"
116 )
117))]
118pub use self::{de::Deserializer, ser::Serializer};
119#[cfg(feature = "serde")]
120pub use self::{
121 de::{from_bytes, from_file, from_reader, from_reader_ascii, from_reader_xml, from_value},
122 ser::{
123 to_file_binary, to_file_xml, to_value, to_writer_binary, to_writer_xml,
124 to_writer_xml_with_options,
125 },
126};
127
128#[cfg(all(test, feature = "serde"))]
129#[macro_use]
130extern crate serde_derive;
131
132#[cfg(all(test, feature = "serde"))]
133mod serde_tests;
134
135fn u64_to_usize(len_u64: u64) -> Option<usize> {
136 let len = len_u64 as usize;
137 if len as u64 != len_u64 {
138 return None; // Too long
139 }
140 Some(len)
141}