Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Add nusb support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio committed Oct 31, 2023
1 parent 14bd3f4 commit a8b564e
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 40 deletions.
22 changes: 5 additions & 17 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,16 @@ jobs:
RUSTFLAGS: "--deny warnings"
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Run Tests
run: cargo test --verbose
run: cargo test --verbose --features rusb

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt, clippy
- name: Check code formatting
run: cargo fmt -- --check
- name: Run Clippy
uses: actions-rs/clippy-check@v1
with:
args: --all-targets
token: ${{ secrets.GITHUB_TOKEN }}
- name: Run Clippy rusb
run: cargo clippy --features rusb
- name: Run Clippy nusb
run: cargo clippy --features nusb
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ file = "src/lib.rs"
search = "https://docs.rs/jaylink/[a-z0-9\\.-]+"
replace = "https://docs.rs/jaylink/{{version}}"

[features]
rusb = ["dep:rusb"]
nusb = ["dep:nusb", "dep:futures-lite"]

[dev-dependencies]
version-sync = "0.9"
env_logger = "0.8.1"
Expand All @@ -52,6 +56,9 @@ jep106 = "0.2.4"
# Public
bitflags = "1.2.1"
# Private
rusb = "0.9.0"
rusb = { version = "0.9.0", optional = true }
nusb = { version = "0.1.0", git = "https://github.com/Dirbaio/nusb", rev = "781207c9202c34cdb677cc4daae7c91ad7736de3", optional = true }
#nusb = { version = "0.1.0", path = "../nusb", optional = true }
futures-lite = { version = "1.13.0", optional = true }
log = "0.4.8"
byteorder = "1.3.2"
3 changes: 1 addition & 2 deletions examples/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ fn run() -> Result<()> {
for devinfo in list {
println!();
print!(
"Bus {:03} Address {:03} Port {:03}: VID={:04x} PID={:04X} – ",
"Bus {:03} Address {:03}: VID={:04x} PID={:04X} – ",
devinfo.bus_number(),
devinfo.address(),
devinfo.port_number(),
devinfo.vid(),
devinfo.pid(),
);
Expand Down
25 changes: 11 additions & 14 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,17 @@ impl<T, E> ResultExt<T, E> for Result<T, E> {
}

macro_rules! error_mapping {
(
$(
$errty:ty => $kind:ident,
)+
) => {
$(
impl Cause for $errty {
const KIND: ErrorKind = ErrorKind::$kind;
}
)+
($errty:ty => $kind:ident) => {
impl Cause for $errty {
const KIND: ErrorKind = ErrorKind::$kind;
}
};
}

error_mapping! {
rusb::Error => Usb,
String => Other,
}
#[cfg(not(feature = "nusb"))]
error_mapping!(rusb::Error => Usb);
#[cfg(feature = "nusb")]
error_mapping!(std::io::Error => Usb);
#[cfg(feature = "nusb")]
error_mapping!(nusb::transfer::TransferError => Usb);
error_mapping!(String => Other);
Loading

0 comments on commit a8b564e

Please sign in to comment.