pub enum Match<T> {
Specific(T),
All,
}Expand description
Represents matching either a specific value or all values of a given type.
This is used in the Pckn type to support matching multiple kinds of notes at once.
Variants§
Implementations§
Source§impl<T> Match<T>
impl<T> Match<T>
Sourcepub const fn as_specific(&self) -> Option<&T>
pub const fn as_specific(&self) -> Option<&T>
Returns a reference to the specific value of this matcher, or None if this is Match::All.
§Example
use clack_common::events::Match;
assert_eq!(Match::Specific(42).as_specific(), Some(&42));
assert_eq!(Match::<u16>::All.as_specific(), None);Sourcepub fn into_specific(self) -> Option<T>
pub fn into_specific(self) -> Option<T>
Returns a reference to the specific value of this matcher, or None if this is Match::All.
§Example
use clack_common::events::Match;
assert_eq!(Match::Specific(42).into_specific(), Some(42));
assert_eq!(Match::<u16>::All.into_specific(), None);Sourcepub const fn is_all(&self) -> bool
pub const fn is_all(&self) -> bool
Returns whether this matcher is Match::All.
§Example
use clack_common::events::Match;
assert!(Match::<u16>::All.is_all());
assert!(!Match::Specific(42).is_all());Sourcepub const fn is_specific(&self) -> bool
pub const fn is_specific(&self) -> bool
Returns whether this matcher is Match::Specific.
§Example
use clack_common::events::Match;
assert!(Match::Specific(42).is_specific());
assert!(!Match::<u16>::All.is_specific());Source§impl<T> Match<T>where
T: PartialEq,
impl<T> Match<T>where
T: PartialEq,
Sourcepub fn matches(&self, other: impl Into<Match<T>>) -> bool
pub fn matches(&self, other: impl Into<Match<T>>) -> bool
Returns true if the given Match matches this one, false otherwise.
This will always return true if any of the two is Match::All. Otherwise, if both values
are specific, they are compared directly (using their PartialEq implementation).
§Example
use clack_common::events::Match;
assert!(Match::Specific(42).matches(42));
assert!(!Match::Specific(42).matches(21));
assert!(Match::Specific(42).matches(Match::All));
assert!(Match::All.matches(42));
assert!(Match::<u16>::All.matches(Match::All));Source§impl Match<u16>
impl Match<u16>
Trait Implementations§
impl<T> Copy for Match<T>where
T: Copy,
impl<T> Eq for Match<T>where
T: Eq,
impl<T> StructuralPartialEq for Match<T>where
T: PartialEq,
Auto Trait Implementations§
impl<T> Freeze for Match<T>where
T: Freeze,
impl<T> RefUnwindSafe for Match<T>where
T: RefUnwindSafe,
impl<T> Send for Match<T>where
T: Send,
impl<T> Sync for Match<T>where
T: Sync,
impl<T> Unpin for Match<T>where
T: Unpin,
impl<T> UnsafeUnpin for Match<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Match<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more