|
9 | 9 | //! ## The Contentline format
|
10 | 10 | //!
|
11 | 11 | //! contentlines are defined in [RFC 5455] (for iCalendar) and [RFC 6350] (vCard). The general format
|
12 |
| -//! distinguishes between **Components** (which represent an entity), |
13 |
| -//! **Properties** (which give attributes to an entity) and **Parameters** |
| 12 | +//! distinguishes between **[Components]** (which represent an entity), |
| 13 | +//! **[Properties]** (which give attributes to an entity) and **[Parameters]** |
14 | 14 | //! (which further describe properties). Components can be a part of other Components, Properties
|
15 |
| -//! are a part of Components and Parameters are a part Properties. |
16 |
| -//! Components have a name, which defines the type a component has and can have multiple |
| 15 | +//! are a part of Components and Parameters are a part of Properties. |
| 16 | +//! Components have a name which defines the type a component has. Components can have multiple |
17 | 17 | //! sub-components and properties. Properties have a name, which defines what property is specified,
|
18 | 18 | //! and a value, which is the content of the attribute. Properties can also have multiple parameters.
|
19 |
| -//! A parameter specifies the property content further and also consists of a name, but can have one |
20 |
| -//! or multiple values. |
| 19 | +//! A parameter specifies the property content further and also consists of a name and can have one |
| 20 | +//! or more values. |
21 | 21 | //! An example of a contentline-formatted file would be:
|
22 | 22 | //! ```txt
|
23 |
| -//! BEGIN:COMPONENT\r\n |
| 23 | +//! BEGIN:MYCOMPONENT\r\n |
24 | 24 | //! PROPERTY-NAME;PARAMETER-NAME=Parameter-value 1,Parameter-value 2:Property value\r\n
|
25 |
| -//! END:COMPONENT\r\n |
| 25 | +//! END:MYCOMPONENT\r\n |
26 | 26 | //! ```
|
27 | 27 | //!
|
28 |
| -//! More on this can be read in the mentioned RFCs and also [RFC 6868], which defines a parameter |
29 |
| -//! value encoding. |
| 28 | +//! More on this can be read in the mentioned RFCs and also [RFC 6868], which defines the method for |
| 29 | +//! escaping parameter values. |
30 | 30 | //!
|
31 | 31 | //! ## Encoding/Parsing
|
| 32 | +//! If you want to decode your Contentline-String, you just have to create a Parser from something |
| 33 | +//! which implements `BufRead` (via [`new`]) or `Read` (via [`from_unbuffered`]). |
| 34 | +//! |
| 35 | +//! The parser can then be called to try to parse the next component. The parser also implements `Iterator`. |
| 36 | +//! |
| 37 | +//! Example: |
| 38 | +//! ``` |
| 39 | +//! use std::io::Cursor; |
| 40 | +//! let input = "BEGIN:comp\r\nmyprop:none\r\nEND:comp\r\n"; |
| 41 | +//! let c=Cursor::new(input); |
| 42 | +//! let mut parser=contentline::Parser::new(c); |
| 43 | +//! let component = parser.next_component().unwrap(); |
| 44 | +//! |
| 45 | +//! ``` |
| 46 | +//! |
| 47 | +//! The parser can also read from files and network sources in the same manner, as long as they implement `Read`. |
| 48 | +//! |
| 49 | +//! |
| 50 | +//! To encode an existing Component struct, you just have to have something implementing `Write` ready. |
| 51 | +//! |
32 | 52 | //!
|
33 | 53 | //! ```
|
| 54 | +//! use contentline::{Component, Encoder}; |
| 55 | +//! let input = Component{ |
| 56 | +//! name:"comp".to_string(), |
| 57 | +//! properties:vec![], |
| 58 | +//! sub_components:vec![] |
| 59 | +//! }; |
| 60 | +//! |
| 61 | +//! let output:Vec<u8> = vec![]; |
| 62 | +//! |
| 63 | +//! let mut encoder=Encoder::new(output); |
| 64 | +//! |
| 65 | +//! encoder.encode(&input); |
34 | 66 | //!
|
35 | 67 | //! ```
|
36 | 68 | //!
|
| 69 | +//! |
| 70 | +//! |
| 71 | +//! |
| 72 | +//! |
| 73 | +//! |
| 74 | +//! |
37 | 75 | //! [RFC 5455]:https://tools.ietf.org/html/rfc5545#section-3.1
|
38 | 76 | //! [RFC 6350]:https://tools.ietf.org/html/rfc6350#section-3.3
|
39 | 77 | //! [RFC 6868]:https://tools.ietf.org/html/rfc6868
|
| 78 | +//! [Components]:struct.Component.html |
| 79 | +//! [Properties]:struct.Property.html |
| 80 | +//! [Parameters]:type.Parameters.html |
| 81 | +//! [`new`]:struct.Parser.html#method.new |
| 82 | +//! [`from_unbuffered`]:struct.Parser.html#method.from_unbuffered |
40 | 83 |
|
41 | 84 |
|
42 | 85 |
|
|
0 commit comments