pub enum Phrase {
Char(AttrChar),
Field(Vec<AttrChar>),
Full(Vec<Vec<AttrChar>>),
}Expand description
Array of fields with optimized data structure
See the module documentation.
Variants§
Char(AttrChar)
Phrase having one field containing one character
Phrase::Char(c) is equivalent to Phrase::Field(vec![c]), which in
turn equals Phrase::Full(vec![vec![c]]).
Field(Vec<AttrChar>)
Phrase made up of one field
Phrase::Field(chars) is equivalent to Phrase::Full(vec![chars]).
Full(Vec<Vec<AttrChar>>)
Phrase containing any number of fields
Implementations§
Source§impl Phrase
impl Phrase
Sourcepub fn zero_fields() -> Self
pub fn zero_fields() -> Self
Returns a phrase containing no fields.
This function requires no heap allocation.
Sourcepub fn one_empty_field() -> Self
pub fn one_empty_field() -> Self
Returns a phrase containing one empty field.
This function requires no heap allocation.
Sourcepub fn is_zero_fields(&self) -> bool
pub fn is_zero_fields(&self) -> bool
Tests whether the phrase has no fields.
Sourcepub fn field_count(&self) -> usize
pub fn field_count(&self) -> usize
Returns the number of fields in the phrase.
Sourcepub fn append(&mut self, other: &mut Phrase)
pub fn append(&mut self, other: &mut Phrase)
Moves all fields of other into self, leaving other empty.
This function joins two phrases into one. It concatenates the last field
of self and the first field of other. Other fields are left intact
in the new phrase.
let mut left = Phrase::Full(vec![vec![a], vec![b], vec![c]]);
let mut right = Phrase::Full(vec![vec![d], vec![e], vec![f]]);
left.append(&mut right);
assert_eq!(
left,
Phrase::Full(vec![vec![a], vec![b], vec![c, d], vec![e], vec![f]])
);
assert!(right.is_zero_fields());That implies joining two single-field phrases results in another single-field phrase.
let mut left = Phrase::Field(vec![a, b, c]);
let mut right = Phrase::Field(vec![d, e, f]);
left.append(&mut right);
assert_eq!(left, Phrase::Field(vec![a, b, c, d, e, f]));
assert!(right.is_zero_fields());let mut left = Phrase::Char(a);
let mut right = Phrase::Char(b);
left.append(&mut right);
assert_eq!(left, Phrase::Field(vec![a, b]));
assert!(right.is_zero_fields());let mut left = Phrase::one_empty_field();
let mut right = Phrase::one_empty_field();
left.append(&mut right);
assert_eq!(left, Phrase::one_empty_field());
assert_eq!(right, Phrase::zero_fields());If either phrase is zero fields, the result is the other.
Sourcepub fn ifs_join(self, vars: &VariableSet) -> Vec<AttrChar>
pub fn ifs_join(self, vars: &VariableSet) -> Vec<AttrChar>
Joins this phrase into a single field, separated by the first IFS character.
This function joins self into a single field, separating each original
field by the first character of variable IFS. If the variable is not
set, fields are separated by a space. If the variable is set but has an
empty value, fields are joined without separation.
Sourcepub fn for_each_char_mut<F>(&mut self, f: F)
pub fn for_each_char_mut<F>(&mut self, f: F)
Applies a function to every character in the phrase.
Trait Implementations§
Source§impl Add for Phrase
See Phrase::append.
impl Add for Phrase
See Phrase::append.
Source§impl AddAssign for Phrase
See Phrase::append.
impl AddAssign for Phrase
See Phrase::append.
Source§fn add_assign(&mut self, other: Phrase)
fn add_assign(&mut self, other: Phrase)
+= operation. Read moreSource§impl IntoIterator for Phrase
impl IntoIterator for Phrase
impl Eq for Phrase
Auto Trait Implementations§
impl Freeze for Phrase
impl RefUnwindSafe for Phrase
impl Send for Phrase
impl Sync for Phrase
impl Unpin for Phrase
impl UnwindSafe for Phrase
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more