Skip to content

Commit

Permalink
Merge pull request #15 from ebds-rs/fixup/variant-reply
Browse files Browse the repository at this point in the history
fixup: variant reply API
  • Loading branch information
ebds-rs authored Aug 18, 2023
2 parents 6b4cc03 + 2505229 commit b063650
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ebds"
version = "0.4.0"
version = "0.4.1"
edition = "2021"
authors = ["EBDS Rust Developers"]
description = "Messages and related types for implementing the EBDS serial communication protocol"
Expand Down
50 changes: 48 additions & 2 deletions src/variant/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::{
index, inner_enum, len, std::fmt, AdvancedBookmarkModeReply, AuxCommand, Banknote,
BaudRateChangeReply, ClearAuditDataRequestAck, ClearAuditDataRequestResults, Control,
DocumentStatus, Error, ExtendedCommand, ExtendedNoteInhibitsReplyAlt, ExtendedNoteReply,
FlashDownloadReply7bit, FlashDownloadReply8bit, MessageOps, MessageType, NoteRetrievedEvent,
NoteRetrievedReply, OmnibusReply, OmnibusReplyOps, QueryApplicationIdReply,
FlashDownloadReply, FlashDownloadReply7bit, FlashDownloadReply8bit, MessageOps, MessageType,
NoteRetrievedEvent, NoteRetrievedReply, OmnibusReply, OmnibusReplyOps, QueryApplicationIdReply,
QueryApplicationPartNumberReply, QueryBootPartNumberReply, QueryDeviceCapabilitiesReply,
QuerySoftwareCrcReply, QueryValueTableReply, QueryVariantIdReply, QueryVariantNameReply,
QueryVariantPartNumberReply, Result, SetEscrowTimeoutReply, StartDownloadReply,
Expand Down Expand Up @@ -203,6 +203,52 @@ impl ReplyVariant {
}
}

/// Gets whether [ReplyVariant] contains a `FlashDownloadReply` message.
pub fn is_flash_download_reply(&self) -> bool {
self.is_flash_download_reply7bit() || self.is_flash_download_reply8bit()
}

/// Gets a reference to the [ReplyVariant] as a [FlashDownloadReply] trait object.
pub fn as_flash_download_reply(&self) -> Result<&dyn FlashDownloadReply> {
match self {
Self::FlashDownloadReply7bit(msg) => Ok(msg),
Self::FlashDownloadReply8bit(msg) => Ok(msg),
_ => Err(Error::failure(format!(
"invalid reply variant, expected FlashDownloadReply, have: {self}"
))),
}
}

/// Convenience alias for [is_flash_download_reply8bit()](Self::is_flash_download_reply8bit).
pub fn is_flash_download_reply_7bit(&self) -> bool {
self.is_flash_download_reply7bit()
}

/// Convenience alias for [as_flash_download_reply7bit()](Self::as_flash_download_reply7bit).
pub fn as_flash_download_reply_7bit(&self) -> Result<&FlashDownloadReply7bit> {
self.as_flash_download_reply7bit()
}

/// Convenience alias for [into_flash_download_reply7bit()](Self::into_flash_download_reply7bit).
pub fn into_flash_download_reply_7bit(self) -> Result<FlashDownloadReply7bit> {
self.into_flash_download_reply7bit()
}

/// Convenience alias for [is_flash_download_reply8bit()](Self::is_flash_download_reply8bit).
pub fn is_flash_download_reply_8bit(&self) -> bool {
self.is_flash_download_reply8bit()
}

/// Convenience alias for [as_flash_download_reply8bit()](Self::as_flash_download_reply8bit).
pub fn as_flash_download_reply_8bit(&self) -> Result<&FlashDownloadReply8bit> {
self.as_flash_download_reply8bit()
}

/// Convenience alias for [into_flash_download_reply8bit()](Self::into_flash_download_reply8bit).
pub fn into_flash_download_reply_8bit(self) -> Result<FlashDownloadReply8bit> {
self.into_flash_download_reply8bit()
}

/// Converts a [ReplyVariant] into a [Banknote].
pub fn into_banknote(&self) -> Result<Banknote> {
match self {
Expand Down

0 comments on commit b063650

Please sign in to comment.