[−][src]Struct manger::common::OneOrMore
Collection struct which stores one or more items of type T
.
This collection is used within the manger crate
to express consuming one of more of an item from a string.
This would be equivalent to the +
operator in
EBNF syntax or
RegEx.
Note
While OneOrMore
is not iterable, the
into_iter
, into_vec
,
ref_vec
and mut_vec
can be used to iterate/create iterators over the items contained within the structs
and do further data manipulation.
Examples
use manger::{Consumable, consume_struct}; use manger::common::OneOrMore; let source = "(2)(3)(7)"; // EncasedInteger will be consuming strings like "(123)" and "(42)" struct EncasedInteger { value: u32 }; consume_struct!( EncasedInteger => [ > '(', value: u32, > ')'; ] ); let (encased_integers, _) = <OneOrMore<EncasedInteger>>::consume_from(source)?; let product: u32 = encased_integers .into_iter() .map(|encased_integer| encased_integer.value) .product(); assert_eq!(product, 42);
Implementations
impl<T> OneOrMore<T>
[src]
pub fn head(&self) -> &T
[src]
Getter for the first item of a OneOrMore<T>
.
This will return a reference to the item that is first consumed and therefore always contains an item.
Examples
use manger::Consumable; use manger::common::OneOrMore; let (items, _) = <OneOrMore<char>>::consume_from("aBcdEFg")?; assert_eq!(*items.head(), 'a');
pub fn tail(&self) -> &Vec<T>
[src]
Getter for the non-first items of a OneOrMore<T>
.
This will return references to the items that is were consumed
after the first item and will be in order of they position within the
source
string. The returned vector possibly has _NO items.
Examples
use manger::Consumable; use manger::common::OneOrMore; let (items, _) = <OneOrMore<char>>::consume_from("aBcdEFg")?; assert_eq!(&items.tail().iter().collect::<String>(), "BcdEFg");
pub fn into_vec(self) -> Vec<T>
[src]
Take ownership self
of type OneOrMore<T>
and return a Vec<T>
owning all
the items self
used to contain.
Since the ownership of the items contained within OneOrMore<T>
will be transfered
into the vector. The OneOrMore<T>
instance cannot be used anymore afterwards.
Examples
use manger::Consumable; use manger::common::OneOrMore; let (items, _) = <OneOrMore<char>>::consume_from("aBcdEFg")?; let uppercased: String = items .into_vec() .into_iter() .filter(|character| character.is_ascii_uppercase()) .collect(); assert_eq!(uppercased, "BEF");
pub fn ref_vec(&self) -> Vec<&T>
[src]
Returns a vector with references to the items in the OneOrMore<T>
.
This will not take ownership of the the items in self
.
Examples
use manger::Consumable; use manger::common::OneOrMore; let (items, _) = <OneOrMore<char>>::consume_from("aBcdEFg")?; let uppercased: String = items .ref_vec() .into_iter() .filter(|character| character.is_ascii_uppercase()) .collect(); assert_eq!(uppercased, "BEF");
pub fn mut_vec(&mut self) -> Vec<&mut T>
[src]
Returns a vector with mutable references to the items in the OneOrMore<T>
.
This will not take ownership of the the items in self
.
Examples
use manger::Consumable; use manger::common::OneOrMore; let (mut items, _) = <OneOrMore<char>>::consume_from("aBcdEFg")?; items .mut_vec() .iter_mut() .filter(|character| character.is_ascii_uppercase()) .for_each(|character| **character = character.to_ascii_lowercase()); let lowercased: String = items.into_iter().collect(); assert_eq!(lowercased, "abcdefg");
Trait Implementations
impl<T: Consumable> Consumable for OneOrMore<T>
[src]
pub fn consume_from(s: &str) -> Result<(Self, &str), ConsumeError>
[src]
pub fn consume_how_many_from(
source: &str
) -> Result<(Self, &str, usize), ConsumeError>
[src]
source: &str
) -> Result<(Self, &str, usize), ConsumeError>
pub fn consume_iter<'a>(source: &'a str) -> ConsumeIter<'a, Self>ⓘNotable traits for ConsumeIter<'a, T>
impl<'a, T> Iterator for ConsumeIter<'a, T> where
T: Consumable, type Item = T;
[src]
Notable traits for ConsumeIter<'a, T>
impl<'a, T> Iterator for ConsumeIter<'a, T> where
T: Consumable, type Item = T;
impl<T: Debug> Debug for OneOrMore<T>
[src]
impl<T: Consumable> IntoIterator for OneOrMore<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for OneOrMore<T> where
T: RefUnwindSafe,
[src]
T: RefUnwindSafe,
impl<T> Send for OneOrMore<T> where
T: Send,
[src]
T: Send,
impl<T> Sync for OneOrMore<T> where
T: Sync,
[src]
T: Sync,
impl<T> Unpin for OneOrMore<T> where
T: Unpin,
[src]
T: Unpin,
impl<T> UnwindSafe for OneOrMore<T> where
T: UnwindSafe,
[src]
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,