From 3c0382b4ef13579d26e052e20846c540901d1d94 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Wed, 8 Jan 2025 18:19:00 +0100 Subject: [PATCH] Cleanup ctaphid-dispatch API This patch flattens the public API of ctaphid-dispatch by making the dispatch and types modules private and re-exporting the relevant types from the root and removes unnecessary re-exports of the types defined by ctaphid-app. --- dispatch/CHANGELOG.md | 1 + dispatch/src/constants.rs | 5 ----- dispatch/src/lib.rs | 14 +++++--------- dispatch/src/types.rs | 14 +------------- 4 files changed, 7 insertions(+), 27 deletions(-) delete mode 100644 dispatch/src/constants.rs diff --git a/dispatch/CHANGELOG.md b/dispatch/CHANGELOG.md index a8e7742..74ff3e6 100644 --- a/dispatch/CHANGELOG.md +++ b/dispatch/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Move the `app` and `command` modules into a separate crate, `ctaphid-app`, and re-export it. - Make `App` trait generic over the response size. - Remove unused `ShortMessage` type. +- Flatten the public module structure and remove unnecessary re-exports. ## [0.1.1] - 2022-08-22 - adjust to `interchange` API change diff --git a/dispatch/src/constants.rs b/dispatch/src/constants.rs deleted file mode 100644 index 4c864d7..0000000 --- a/dispatch/src/constants.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub const PACKET_SIZE: usize = 64; - -// 7609 bytes -pub const MESSAGE_SIZE: usize = PACKET_SIZE - 7 + 128 * (PACKET_SIZE - 5); - diff --git a/dispatch/src/lib.rs b/dispatch/src/lib.rs index bd41888..8f00a84 100644 --- a/dispatch/src/lib.rs +++ b/dispatch/src/lib.rs @@ -13,14 +13,10 @@ extern crate delog; generate_macros!(); -pub mod dispatch; -pub mod types; +mod dispatch; +mod types; -pub mod app { - pub use crate::types::AppResult; - pub use ctaphid_app::{App, Command, Error}; -} +pub use ctaphid_app as app; -pub mod command { - pub use ctaphid_app::{Command, VendorCommand}; -} +pub use dispatch::Dispatch; +pub use types::{Channel, InterchangeResponse, Message, Requester, Responder, MESSAGE_SIZE}; diff --git a/dispatch/src/types.rs b/dispatch/src/types.rs index a8d034b..a7fa6c7 100644 --- a/dispatch/src/types.rs +++ b/dispatch/src/types.rs @@ -1,19 +1,9 @@ +use ctaphid_app::{Command, Error}; use heapless_bytes::Bytes; -pub use ctaphid_app::Error; - -// // 7609 bytes is max message size for ctaphid -// type U6144 = >::Output; -// type U7168 = >::Output; -// pub type U7609 = >::Output; -// pub type U7609 = heapless::consts::U4096; - -// TODO: find reasonable size -// pub type Message = heapless::Vec; pub const MESSAGE_SIZE: usize = 7609; pub type Message = Bytes; -pub type AppResult = core::result::Result<(), Error>; /// Wrapper struct that implements [`Default`][] to be able to use [`response_mut`](interchange::Responder::response_mut) pub struct InterchangeResponse(pub Result); @@ -36,8 +26,6 @@ impl From for Result { } } -pub use crate::command::Command; - pub type Responder<'pipe> = interchange::Responder<'pipe, (Command, Message), InterchangeResponse>; pub type Requester<'pipe> = interchange::Requester<'pipe, (Command, Message), InterchangeResponse>; pub type Channel = interchange::Channel<(Command, Message), InterchangeResponse>;