Struct ItemStr

Source
pub struct ItemStr { /* private fields */ }
Expand description

This item is used to read an string value from the TOML file

Implementations§

Source§

impl ItemStr

Source

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

Constructs a new instance of the ItemUsize object.

Source

pub fn add_to(self, group: &mut TomlDef) -> StringValue

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 length the string can be.

Source

pub fn max(self, max: usize) -> Self

Defines the maximum length the string can be.

Source

pub fn optional(self) -> Self

Marks the item as optional without providing a default value.

Source

pub fn default<T: AsRef<str>>(self, default: T) -> 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.

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.