pub struct ItemUsize { /* private fields */ }Expand description
This item is used to read an 64 bit unsigned number from the TOML file.
Implementations§
Source§impl ItemUsize
impl ItemUsize
Sourcepub fn with_name<T: AsRef<str>>(name: T) -> ItemUsize
pub fn with_name<T: AsRef<str>>(name: T) -> ItemUsize
Constructs a new instance of the ItemUsize object.
Sourcepub fn add_to(self, group: &mut TomlDef) -> UsizeValue
pub fn add_to(self, group: &mut TomlDef) -> UsizeValue
Adds the item to a group and returns an option that will receive the item’s value when the file is loaded. Basically this allows a program to receive a value laoded from the file without getting the TomlData object that was created.
§Examples
use valid_toml::{TomlDef, ItemStr, ItemUsize};
let file = r#"
password = "secret"
count = 15
"#;
let mut def = TomlDef::new();
let password = ItemStr::with_name("password").min(3).max(8).add_to(&mut def);
let count = ItemUsize::with_name("count").optional().add_to(&mut def);
let file = def.parse_toml(file).unwrap();
assert_eq!(password.get(), "secret");
assert_eq!(count.get(), 15);Sourcepub fn min(self, min: usize) -> Self
pub fn min(self, min: usize) -> Self
Defines the minimum value (inclusive) of the value read from the file.
§Panics
This method will panic if max is set and is less than min. The method will also panic if the value is greater than i64::MAX, which is the largest value that can be read from the file.
Sourcepub fn max(self, max: usize) -> Self
pub fn max(self, max: usize) -> Self
Defines the maximum value (inclusive) of the value read from the file.
§Panics
This method will panic if min is set and is greater than max. The method will also panic if the value is greater than i64::MAX, which is the largest value that can be read from the file.
Sourcepub fn default(self, default: usize) -> Self
pub fn default(self, default: usize) -> Self
Defines the default value for the item. This method makes the item optional. The default value will only be used if the parent group exists.
§Panics
This method will panic if default is greater than i64::MAX as that is the largest value that can be read from a TOML file.