Expand description
Denotes a set of settings as a simple sorted map of Key-Value pairs.
Each entry in this map consists of a key of type Key
and a value of type Option<Value>
.
For more information about why values are wrapped in Option
please refer to the
documentation of the type Value
.
How to use Settings
Since Settings
is just an alias for BTreeMap
, you can construct them fairly easily from an array of tuples:
// Create a new Settings object with 1 key-value pair "url=https://example.com"
let my_settings_one = renvy::Settings::from([("url".into(), Some("https://example.com".into()))]);
assert_eq!(my_settings_one.get("url").unwrap(), &Some("https://example.com".into()));
// Create a new Settings object with 1 key-value pair where the value is empty "url="
let my_settings_one = renvy::Settings::from([("url".into(), None)]);
assert_eq!(my_settings_one.get("url").unwrap(), &None);
Besides that, crate::deserialize()
will also return an instance of Settings
:
// Settings objects will also be returned from renvy::deserialize()
let my_settings_deserialized = renvy::deserialize("url=https://example.com".into());
assert_eq!(my_settings_deserialized.get("url".into()).unwrap(), &Some("https://example.com".into()));