Skip to main content

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;
92mod macros;
93
94#[cfg(feature = "serde")]
95pub use data::Data;
96pub use date::{Date, InvalidXmlDate};
97pub use dictionary::Dictionary;
98pub use error::Error;
99pub use integer::Integer;
100pub use stream::XmlWriteOptions;
101pub use uid::Uid;
102pub use value::Value;
103
104// Optional serde module
105#[cfg(feature = "serde")]
106#[macro_use]
107extern crate serde;
108#[cfg(feature = "serde")]
109mod de;
110#[cfg(feature = "serde")]
111mod ser;
112#[cfg(all(
113    feature = "serde",
114    any(
115        test,
116        feature = "enable_unstable_features_that_may_break_with_minor_version_bumps"
117    )
118))]
119pub use self::{de::Deserializer, ser::Serializer};
120#[cfg(feature = "serde")]
121pub use self::{
122    de::{from_bytes, from_file, from_reader, from_reader_ascii, from_reader_xml, from_value},
123    ser::{
124        to_file_binary, to_file_xml, to_value, to_writer_binary, to_writer_xml,
125        to_writer_xml_with_options,
126    },
127};
128
129#[cfg(all(test, feature = "serde"))]
130#[macro_use]
131extern crate serde_derive;
132
133#[cfg(all(test, feature = "serde"))]
134mod serde_tests;
135
136fn u64_to_usize(len_u64: u64) -> Option<usize> {
137    usize::try_from(len_u64).ok()
138}