Debian Codegraph @

third_party/rust/rust-ini/README.rst

raw
1 INI in Rust
2 -----------
3
4 .. image:: https://travis-ci.org/zonyitoo/rust-ini.svg?branch=master
5 :target: https://travis-ci.org/zonyitoo/rust-ini
6
7 .. image:: https://img.shields.io/crates/v/rust-ini.svg
8 :target: https://crates.io/crates/rust-ini
9
10 INI_ is an informal standard for configuration files for some platforms or software. INI files are simple text files with a basic structure composed of "sections" and "properties".
11
12 .. _INI: http://en.wikipedia.org/wiki/INI_file
13
14 This is an INI file parser in Rust_.
15
16 .. _Rust: http://www.rust-lang.org/
17
18 .. code:: toml
19
20 [dependencies]
21 rust-ini = "0.10"
22
23 Usage
24 =====
25
26 * Create a Ini configuration file.
27
28 .. code:: rust
29
30 extern crate ini;
31 use ini::Ini;
32
33 fn main() {
34 let mut conf = Ini::new();
35 conf.with_section(None)
36 .set("encoding", "utf-8");
37 conf.with_section(Some("User".to_owned()))
38 .set("given_name", "Tommy")
39 .set("family_name", "Green")
40 .set("unicode", "Raspberry树莓");
41 conf.with_section(Some("Book".to_owned()))
42 .set("name", "Rust cool");
43 conf.write_to_file("conf.ini").unwrap();
44 }
45
46 Then you will get ``conf.ini``
47
48 .. code:: ini
49
50 encoding=utf-8
51
52 [User]
53 given_name=Tommy
54 family_name=Green
55 unicode=Raspberry\x6811\x8393
56
57 [Book]
58 name=Rust cool
59
60 * Read from file ``conf.ini``
61
62 .. code:: rust
63
64 extern crate ini;
65 use ini::Ini;
66
67 fn main() {
68 let conf = Ini::load_from_file("conf.ini").unwrap();
69
70 let section = conf.section(Some("User".to_owned())).unwrap();
71 let tommy = section.get("given_name").unwrap();
72 let green = section.get("family_name").unwrap();
73
74 println!("{:?} {:?}", tommy, green);
75
76 // iterating
77 for (sec, prop) in &conf {
78 println!("Section: {:?}", sec);
79 for (key, value) in &prop {
80 println!("{:?}:{:?}", key, value);
81 }
82 }
83 }
84
85 * More details could be found in `examples`.
86
87 License
88 =======
89
90 The MIT License (MIT)
91
92 Copyright (c) 2014 Y. T. CHUNG
93
94 Permission is hereby granted, free of charge, to any person obtaining a copy of
95 this software and associated documentation files (the "Software"), to deal in
96 the Software without restriction, including without limitation the rights to
97 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
98 the Software, and to permit persons to whom the Software is furnished to do so,
99 subject to the following conditions:
100
101 The above copyright notice and this permission notice shall be included in all
102 copies or substantial portions of the Software.
103
104 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
105 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
106 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
107 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
108 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
109 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.