Debian Codegraph @

third_party/rust/plist/src/lib.rs

raw
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 #![allow(warnings)] // Third-party
76
77 pub mod dictionary;
78
79 #[cfg(feature = "enable_unstable_features_that_may_break_with_minor_version_bumps")]
80 pub mod stream;
81 #[cfg(not(feature = "enable_unstable_features_that_may_break_with_minor_version_bumps"))]
82 mod stream;
83
84 mod date;
85 mod error;
86 mod integer;
87 mod uid;
88 mod value;
89
90 pub use date::Date;
91 pub use dictionary::Dictionary;
92 pub use error::Error;
93 pub use integer::Integer;
94 pub use stream::XmlWriteOptions;
95 pub use uid::Uid;
96 pub use value::Value;
97
98 // Optional serde module
99 #[cfg(feature = "serde")]
100 #[macro_use]
101 extern crate serde;
102 #[cfg(feature = "serde")]
103 mod de;
104 #[cfg(feature = "serde")]
105 mod ser;
106 #[cfg(all(
107 feature = "serde",
108 any(
109 test,
110 feature = "enable_unstable_features_that_may_break_with_minor_version_bumps"
111 )
112 ))]
113 pub use self::{de::Deserializer, ser::Serializer};
114 #[cfg(feature = "serde")]
115 pub use self::{
116 de::{from_bytes, from_file, from_reader, from_reader_xml},
117 ser::{
118 to_file_binary, to_file_xml, to_writer_binary, to_writer_xml, to_writer_xml_with_options,
119 },
120 };
121
122 #[cfg(all(test, feature = "serde"))]
123 #[macro_use]
124 extern crate serde_derive;
125
126 #[cfg(all(test, feature = "serde"))]
127 mod serde_tests;
128
129 fn u64_to_usize(len_u64: u64) -> Option<usize> {
130 let len = len_u64 as usize;
131 if len as u64 != len_u64 {
132 return None; // Too long
133 }
134 Some(len)
135 }