ItemUsize

Struct ItemUsize 

Source
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

Source

pub fn with_name<T: AsRef<str>>(name: T) -> ItemUsize

Constructs a new instance of the ItemUsize object.

Source

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);
Source

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.

Source

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.

Source

pub fn optional(self) -> Self

Marks the item as optional without providing a default value.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.