-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from ssp-rs/events/dispense-event
events: add `DispenseEvent`
- Loading branch information
Showing
24 changed files
with
347 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use crate::{impl_default, std::fmt, PayoutDenominationList}; | ||
|
||
use super::Method; | ||
|
||
/// Represents a [Dispense](crate::PayoutDenominationCommand) event. | ||
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)] | ||
pub struct DispenseEvent(PayoutDenominationList); | ||
|
||
impl DispenseEvent { | ||
/// Creates a new [DispenseEvent]. | ||
pub const fn new() -> Self { | ||
Self(PayoutDenominationList::new()) | ||
} | ||
|
||
/// Creates a new [DispenseEvent] with the provided parameter. | ||
pub const fn create(list: PayoutDenominationList) -> Self { | ||
Self(list) | ||
} | ||
|
||
/// Gets the [Method] for the [DispenseEvent]. | ||
pub const fn method() -> Method { | ||
Method::Dispense | ||
} | ||
|
||
/// Converts the [DispenseEvent] to a string. | ||
pub const fn to_str(&self) -> &'static str { | ||
Self::method().to_str() | ||
} | ||
|
||
/// Gets the length of the event in a [PollResponse](crate::PollResponse). | ||
pub const fn len() -> usize { | ||
1 | ||
} | ||
|
||
/// Gets a reference to the inner representation of the [DispenseEvent]. | ||
pub const fn as_inner(&self) -> &PayoutDenominationList { | ||
&self.0 | ||
} | ||
|
||
/// Gets a mutable reference to the inner representation of the [DispenseEvent]. | ||
pub fn as_inner_mut(&mut self) -> &mut PayoutDenominationList { | ||
&mut self.0 | ||
} | ||
|
||
/// Consumes the [DispenseEvent], returning its inner repreesentation. | ||
pub fn to_inner(self) -> PayoutDenominationList { | ||
self.0 | ||
} | ||
} | ||
|
||
impl From<&DispenseEvent> for &'static str { | ||
fn from(val: &DispenseEvent) -> Self { | ||
val.to_str() | ||
} | ||
} | ||
|
||
impl From<DispenseEvent> for &'static str { | ||
fn from(val: DispenseEvent) -> Self { | ||
(&val).into() | ||
} | ||
} | ||
|
||
impl fmt::Display for DispenseEvent { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, r#"{{"{}"}}"#, self.to_str()) | ||
} | ||
} | ||
|
||
impl_default!(DispenseEvent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.