Skip to main content

Pattern

Struct Pattern 

Source
pub struct Pattern<'a>(/* private fields */);
Expand description

A pattern: a sequence of parts with no empty Text and no two adjacent Text parts (Pattern::push merges and drops accordingly).

The representation stores one part inline, so a placeholder-free message needs no allocation (the D1 target).

Implementations§

Source§

impl<'a> Pattern<'a>

Source

pub const fn new() -> Self

The empty pattern (does not allocate).

Source

pub fn with_capacity(capacity: usize) -> Self

An empty pattern with room for capacity parts: no allocation for 0 or 1 part, one allocation of exactly capacity parts otherwise.

Source

pub fn from_text(text: Cow<'a, str>) -> Self

The pattern holding just text; "" gives the empty pattern. Does not allocate.

Source

pub fn push(&mut self, part: PatternPart<'a>)

Appends part: an empty Text is dropped, and a Text after a Text is merged into it (which makes the merged text owned).

Source

pub fn parts(&self) -> &[PatternPart<'a>]

The parts, in order.

Source

pub fn iter(&self) -> Iter<'_, PatternPart<'a>> ⓘ

Iterates over the parts, in order.

Source

pub fn len(&self) -> usize

How many parts.

Source

pub fn is_empty(&self) -> bool

No parts.

Source

pub fn as_simple_text(&self) -> Option<&str>

Some for the empty pattern ("") and for a pattern that is a single Text part; None if it has a placeholder.

Source

pub fn into_parts(self) -> Vec<PatternPart<'a>>

The parts as a vector (allocates unless the pattern already holds one).

Source

pub fn into_owned(self) -> Pattern<'static>

The same pattern with every string owned.

Trait Implementations§

Source§

impl<'a> Clone for Pattern<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Pattern<'_>

Source§

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

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

impl<'a> Default for Pattern<'a>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de: 'a, 'a> Deserialize<'de> for Pattern<'a>

Available on crate feature serde only.
Source§

fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Pattern<'_>

Source§

impl<'a> From<Vec<PatternPart<'a>>> for Pattern<'a>

Source§

fn from(parts: Vec<PatternPart<'a>>) -> Self

Keeps the vector’s allocation when it already satisfies the pattern invariants (no empty or adjacent Text); otherwise normalizes.

Source§

impl<'a> FromIterator<PatternPart<'a>> for Pattern<'a>

Source§

fn from_iter<I: IntoIterator<Item = PatternPart<'a>>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Hash for Pattern<'_>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'p, 'a> IntoIterator for &'p Pattern<'a>

Source§

type Item = &'p PatternPart<'a>

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'p, PatternPart<'a>>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Pattern<'_>

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for Pattern<'_>

Available on crate feature serde only.
Source§

fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Pattern<'a>

§

impl<'a> RefUnwindSafe for Pattern<'a>

§

impl<'a> Send for Pattern<'a>

§

impl<'a> Sync for Pattern<'a>

§

impl<'a> Unpin for Pattern<'a>

§

impl<'a> UnsafeUnpin for Pattern<'a>

§

impl<'a> UnwindSafe for Pattern<'a>

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> 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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.