pub enum Pattern {
Wildcard(Span),
Binding(Ident),
Literal {
value: LiteralValue,
span: Span,
},
Variant {
type_name: Option<Ident>,
variant: Ident,
bindings: Vec<PatternBinding>,
span: Span,
},
Refined {
inner: Box<Pattern>,
predicate: Refinement,
span: Span,
},
Or(Vec<Pattern>, Span),
}Expand description
A pattern (v0.2 §3.8). Patterns appear in match arms and as the
right-hand side of the is operator.
Variants§
Wildcard(Span)
_ — matches any value, no bindings.
Binding(Ident)
A lowercase identifier — binds the whole value to name and matches
anything (ADR 0169). At the top of a match arm it binds the scrutinee
(n if n > 0 => …); inside a payload position it binds the field
(Some(user)). The uppercase-led counterpart is a nullary Pattern::Variant.
Literal
A literal pattern — 31, "english", true (v0.130 §2.3.4). Matches a
primitive scrutinee (Int/String/Bool) by value equality. The
admitted set mirrors ADR 0001’s closed literal set (integers — including
a leading unary minus — strings, and booleans); Float/() are not
admitted as patterns.
Variant
Variant or Variant(bindings) or TypeName.Variant(bindings). Each
payload binding is itself a Pattern (ADR 0169), so payloads nest:
Some(Ok(x)), Err(PollClosed).
Fields
bindings: Vec<PatternBinding>Payload bindings (empty for nullary variants).
Refined
p 'where' refinement-predicate — a refinement guard on a pattern
(#472). Matches when inner matches and the scrutinee satisfies
predicate at runtime. v1 admits only Wildcard as inner (no
binding form yet); refutable — never counts toward exhaustiveness or
as a catch-all arm, the same treatment as an if guard (§2.3.4).
Or(Vec<Pattern>, Span)
p₁ | p₂ | … | pₙ — an or-pattern (#474 §2.3.4): matches if any
alternative matches. Left-associative |, flattened by the parser’s
chain fold into one Vec — an alternative is always a leaf
(Wildcard/Binding/Literal/Variant), never itself an Or
(there is no parenthesized-pattern syntax to nest one inside another).
Well-typedness (checked, not parsed): every alternative binds the same
set of names, a name shared across alternatives has the same type
(including refinement) in each, and every alternative matches the same
value type.
Implementations§
Source§impl Pattern
impl Pattern
pub fn span(&self) -> Span
Sourcepub fn bound_names(&self) -> Vec<&Ident>
pub fn bound_names(&self) -> Vec<&Ident>
Every identifier this pattern binds into scope, recursively (_ and
nullary variants bind nothing). Used by the resolver and the checker to
populate an arm’s scope, and by the guard to see the arm’s bindings.
For Pattern::Or this returns the first alternative’s names — the
checker separately verifies (#474 Rule 1) that every alternative binds
the same set, so this is a defensive default when that rule is
violated, not a semantic choice among alternatives.
Sourcepub fn is_wildcard(&self) -> bool
pub fn is_wildcard(&self) -> bool
True when this pattern matches every value and binds nothing — a bare
_. A Pattern::Binding also matches everything but does bind, so it
is not a pure wildcard.
Sourcepub fn is_irrefutable(&self) -> bool
pub fn is_irrefutable(&self) -> bool
True when this pattern matches every value (a _ or a name binding),
i.e. it is irrefutable and covers the position for exhaustiveness. An
Pattern::Or is irrefutable when any alternative is — _ in any
position already makes the whole pattern match everything.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Pattern
impl RefUnwindSafe for Pattern
impl Send for Pattern
impl Sync for Pattern
impl Unpin for Pattern
impl UnsafeUnpin for Pattern
impl UnwindSafe for Pattern
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> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);