Skip to main content

Match

Enum Match 

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

§

Specific(T)

Matches a specific value.

§

All

Matches all values.

Implementations§

Source§

impl<T> Match<T>

Source

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);
Source

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);
Source

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());
Source

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,

Source

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>

Source

pub const fn from_raw(raw: i16) -> Match<u16>

Creates the Match that corresponds to the given raw C-FFI compatible i16 type.

Source

pub const fn to_raw(&self) -> i16

Returns the raw C-FFI compatible i16 type that corresponds to this Match.

If this matches a specific value, it is returned. Otherwise, if this matches all values, it returns -1.

Source§

impl Match<u32>

Source

pub const fn from_raw(raw: i32) -> Match<u32>

Creates the Match that corresponds to the given raw C-FFI compatible i32 type.

Source

pub const fn to_raw(&self) -> i32

Returns the raw C-FFI compatible i32 type that corresponds to this Match.

If this matches a specific value, it is returned. Otherwise, if this matches all values, it returns -1.

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> Match<T>

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<T> Copy for Match<T>
where T: Copy,

Source§

impl<T> Debug for Match<T>
where T: Debug,

Source§

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

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

impl<T> Eq for Match<T>
where T: Eq,

Source§

impl From<ClapId> for Match<u32>

Source§

fn from(value: ClapId) -> Match<u32>

Converts to this type from the input type.
Source§

impl<T> From<T> for Match<T>

Source§

fn from(value: T) -> Match<T>

Converts to this type from the input type.
Source§

impl From<u8> for Match<u16>

Source§

fn from(value: u8) -> Match<u16>

Converts to this type from the input type.
Source§

impl From<u8> for Match<u32>

Source§

fn from(value: u8) -> Match<u32>

Converts to this type from the input type.
Source§

impl From<u16> for Match<u32>

Source§

fn from(value: u16) -> Match<u32>

Converts to this type from the input type.
Source§

impl<T> Hash for Match<T>
where T: Hash,

Source§

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

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<T> PartialEq for Match<T>
where T: PartialEq,

Source§

fn eq(&self, other: &Match<T>) -> bool

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

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

Inequality operator !=. Read more
Source§

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> 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.