Skip to content

Commit d800da6

Browse files
committed
Update, improve docs
1 parent dd08357 commit d800da6

File tree

1 file changed

+53
-10
lines changed

1 file changed

+53
-10
lines changed

src/lib.rs

+53-10
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,77 @@
99
//! ## The Contentline format
1010
//!
1111
//! 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]**
1414
//! (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
1717
//! sub-components and properties. Properties have a name, which defines what property is specified,
1818
//! 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.
2121
//! An example of a contentline-formatted file would be:
2222
//! ```txt
23-
//! BEGIN:COMPONENT\r\n
23+
//! BEGIN:MYCOMPONENT\r\n
2424
//! PROPERTY-NAME;PARAMETER-NAME=Parameter-value 1,Parameter-value 2:Property value\r\n
25-
//! END:COMPONENT\r\n
25+
//! END:MYCOMPONENT\r\n
2626
//! ```
2727
//!
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.
3030
//!
3131
//! ## 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+
//!
3252
//!
3353
//! ```
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);
3466
//!
3567
//! ```
3668
//!
69+
//!
70+
//!
71+
//!
72+
//!
73+
//!
74+
//!
3775
//! [RFC 5455]:https://tools.ietf.org/html/rfc5545#section-3.1
3876
//! [RFC 6350]:https://tools.ietf.org/html/rfc6350#section-3.3
3977
//! [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
4083
4184

4285

0 commit comments

Comments
 (0)