Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: create a usb backend trait #57

Merged
merged 1 commit into from
Sep 8, 2024
Merged

Conversation

louib
Copy link
Owner

@louib louib commented Sep 7, 2024

This commit creates a Backend trait that encapsulates all the functions that are specific to a backend (rusb or nusb). This has the following advantages:

  • All the backend-specific code is out of src/lib.rs and moved into the usb module and submodules.
  • The number of cfg compilation directives is reduced drastically
  • It will be easier to change the backend dynamically by changing which trait object is used as a backend
  • It will also be easier to unit test the non-backend part of the codebase, by creating a MockBackend.

I'm not able to implement the dynamic backend feature at the moment, since I need to find a way to deal with the requirements for trait objects in Rust. This can definitely happen in a future PR.

@louib louib force-pushed the implement-usb-backend-trait branch 2 times, most recently from d28063a to 977b9fa Compare September 7, 2024 19:48
@louib louib marked this pull request as ready for review September 7, 2024 19:54
@louib louib requested a review from droidmonkey as a code owner September 7, 2024 19:54
@louib louib force-pushed the implement-usb-backend-trait branch from 977b9fa to 871dce9 Compare September 7, 2024 20:08
pub const CHALLENGE_SIZE: usize = 64;
use usb::{Backend, BackendType, Flags, Frame, CHALLENGE_SIZE};

pub use usb::Device;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-exporting the Device struct to avoid introducing a breaking change.

@louib louib enabled auto-merge (squash) September 8, 2024 00:58
@louib louib disabled auto-merge September 8, 2024 23:07
@louib louib merged commit 9090a69 into master Sep 8, 2024
6 checks passed
@louib louib deleted the implement-usb-backend-trait branch September 8, 2024 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant