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>
impl<'a> Pattern<'a>
Sourcepub fn with_capacity(capacity: usize) -> Self
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.
Sourcepub fn from_text(text: Cow<'a, str>) -> Self
pub fn from_text(text: Cow<'a, str>) -> Self
The pattern holding just text; "" gives the empty pattern. Does not
allocate.
Sourcepub fn push(&mut self, part: PatternPart<'a>)
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).
Sourcepub fn parts(&self) -> &[PatternPart<'a>]
pub fn parts(&self) -> &[PatternPart<'a>]
The parts, in order.
Sourcepub fn iter(&self) -> Iter<'_, PatternPart<'a>> ⓘ
pub fn iter(&self) -> Iter<'_, PatternPart<'a>> ⓘ
Iterates over the parts, in order.
Sourcepub fn as_simple_text(&self) -> Option<&str>
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.
Sourcepub fn into_parts(self) -> Vec<PatternPart<'a>>
pub fn into_parts(self) -> Vec<PatternPart<'a>>
The parts as a vector (allocates unless the pattern already holds one).
Sourcepub fn into_owned(self) -> Pattern<'static>
pub fn into_owned(self) -> Pattern<'static>
The same pattern with every string owned.
Trait Implementations§
Source§impl<'de: 'a, 'a> Deserialize<'de> for Pattern<'a>
Available on crate feature serde only.
impl<'de: 'a, 'a> Deserialize<'de> for Pattern<'a>
serde only.Source§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
impl Eq for Pattern<'_>
Source§impl<'a> From<Vec<PatternPart<'a>>> for Pattern<'a>
impl<'a> From<Vec<PatternPart<'a>>> for Pattern<'a>
Source§fn from(parts: Vec<PatternPart<'a>>) -> Self
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.