Phrase

Enum Phrase 

Source
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

Source

pub fn zero_fields() -> Self

Returns a phrase containing no fields.

This function requires no heap allocation.

Source

pub fn one_empty_field() -> Self

Returns a phrase containing one empty field.

This function requires no heap allocation.

Source

pub fn is_zero_fields(&self) -> bool

Tests whether the phrase has no fields.

Source

pub fn field_count(&self) -> usize

Returns the number of fields in the phrase.

Source

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.

Source

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.

Source

pub fn for_each_char_mut<F>(&mut self, f: F)
where F: FnMut(&mut AttrChar),

Applies a function to every character in the phrase.

Trait Implementations§

Source§

impl Add for Phrase

Source§

type Output = Phrase

The resulting type after applying the + operator.
Source§

fn add(self, other: Phrase) -> Self

Performs the + operation. Read more
Source§

impl AddAssign for Phrase

Source§

fn add_assign(&mut self, other: Phrase)

Performs the += operation. Read more
Source§

impl Clone for Phrase

Source§

fn clone(&self) -> Phrase

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Phrase

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<AttrChar> for Phrase

Source§

fn from(c: AttrChar) -> Self

Converts to this type from the input type.
Source§

impl From<Phrase> for Vec<Vec<AttrChar>>

Source§

fn from(phrase: Phrase) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<AttrChar>> for Phrase

Source§

fn from(chars: Vec<AttrChar>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Vec<AttrChar>>> for Phrase

Source§

fn from(fields: Vec<Vec<AttrChar>>) -> Self

Converts to this type from the input type.
Source§

impl IntoIterator for Phrase

Source§

type Item = Vec<AttrChar>

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Phrase

Source§

fn eq(&self, other: &Phrase) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.