Skip to content

Commit bfaee70

Browse files
committed
Bump to 1.1.0
1 parent 66d5889 commit bfaee70

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ini"
3-
version = "1.0.2"
3+
version = "1.1.0"
44
authors = ["QEDK <qedk.en@gmail.com>"]
55
edition = "2018"
66
description = "A simple macro built on top of configparser to load and parse ini files. You can use this to write Rust programs which can be customized by end users easily."

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Essentially, the syntax consists of sections, each of which can which contains k
2626
You can install this easily via `cargo` by including it in your `Cargo.toml` file like:
2727
```TOML
2828
[dependencies]
29-
ini = "1.0.2"
29+
ini = "1.1.0"
3030
```
3131

3232
### The `ini!` macro
@@ -56,6 +56,39 @@ let val = map.unwrap()["section"]["key"].clone().unwrap();
5656
// Note the extra unwrap here, which is required because our HashMap is inside a Result type.
5757
```
5858

59+
### The `inistr!` macro
60+
The `inistr!` macro allows you to simply get a hashmap of type `HashMap<String, HashMap<String, Option<String>>>` for a list of strings.
61+
```rust
62+
#[macro_use]
63+
extern crate ini;
64+
65+
fn main() {
66+
let configstring = "[section]
67+
key = value
68+
top = secret";
69+
let map = inistr!(configstring);
70+
// Proceed to use normal HashMap functions on the map:
71+
let val = map["section"]["top"].clone().unwrap();
72+
// The type of the map is HashMap<String, HashMap<String, Option<String>>>
73+
assert_eq!(val, "secret"); // value accessible!
74+
75+
// To load multiple string, just do:
76+
let (map1, map2, map3) = inistr!(&String::from(configstring), configstring, "[section]
77+
key = value
78+
top = secret");
79+
// Each map is a cloned hashmap with no relation to other ones
80+
}
81+
```
82+
If loading a file fails or the parser is unable to parse the file, the code will `panic` with an appropriate error. In case, you want to handle this
83+
gracefully, it's recommended you use the `safe` metavariable instead. This will make sure your code does not panic and instead exists as a
84+
`Result<HashMap, String>` type and let you deal with errors gracefully.
85+
```rust
86+
let map = inistr!(safe strvariable_or_strliteral);
87+
// Proceed to use normal HashMap functions on the map:
88+
let val = map.unwrap()["section"]["key"].clone().unwrap();
89+
// Note the extra unwrap here, which is required because our HashMap is inside a Result type.
90+
```
91+
5992
## Supported datatypes
6093
`configparser` does not guess the datatype of values in configuration files and stores everything as strings, same applies to `ini`. If you need getters that parse the values for you, you might want to use `configparser`. You can ofcourse just choose to parse the string values yourself.
6194
```rust

0 commit comments

Comments
 (0)