[][src]Struct mininip::datas::Identifier

pub struct Identifier { /* fields omitted */ }

The identifier of a variable, which is its identity. Of course, this type is Hash because it may be used as a key in a HashMap

Methods

impl Identifier[src]

pub fn new(section: Option<String>, name: String) -> Identifier[src]

Creates an identifier with a valid section name and a valid name

Panics

Panics if either section or name is an invalid identifier according to Identifier::is_valid

pub fn is_valid(ident: &str) -> bool[src]

Returns true if the given string is a valid identifier and false otherwise

A valid identifier is defined as a string of latin alphanumeric characters and any of _, ~, -, ., :, $ and space starting with a latin alphabetic one or any of ., $ or :. All of these characters must be ASCII

Notes

Since the INI file format is not really normalized, this definition may evolve in the future. In fact, I will avoid when possible to make a stronger rule, in order to keep backward compatibility

Examples

use mininip::datas::Identifier;
 
assert!(Identifier::is_valid("identifier"));
assert!(Identifier::is_valid("digits1230"));
assert!(Identifier::is_valid("UPPERCASE_AND_UNDERSCORES"));
assert!(Identifier::is_valid("contains spaces inside"));
assert!(!Identifier::is_valid("123_starts_with_a_digit"));
assert!(!Identifier::is_valid("invalid_characters;!\\~"));
assert!(!Identifier::is_valid("é_is_unicode"));
assert!(!Identifier::is_valid(" starts_with_a_space"));

pub fn name(&self) -> &str[src]

Returns the name of the variable as a reference

pub fn section(&self) -> Option<&str>[src]

Returns the section of the variable which may be a named section as Some(name) or the "global scope" wich is None

pub fn change_name(&mut self, name: String)[src]

Change the name of the variable

Panics

Panics if name is invalid according to Identifier::is_valid

pub fn change_section(&mut self, section: Option<String>)[src]

Changes the section of the variable. section may be Some(name) with name as the name of the section of None for the "global scope"

Panics

Panics if section is invalid according to Identifier::is_valid

Trait Implementations

impl Clone for Identifier[src]

impl Debug for Identifier[src]

impl Display for Identifier[src]

impl Eq for Identifier[src]

impl Hash for Identifier[src]

impl PartialEq<Identifier> for Identifier[src]

impl StructuralEq for Identifier[src]

impl StructuralPartialEq for Identifier[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.