jamesmunns / postcard-rpc

An RPC layer for postcard based protocols
Apache License 2.0
90 stars 21 forks source link

Remove direct `embassy-usb-driver` dependency #19

Closed avsaase closed 6 months ago

avsaase commented 6 months ago

This removes the direct dependency on embassy-usb-driver and instead uses the re-exported version from embassy-usb. Without these changes I wasn't able to get postcard-rpc to compile in my project with the following errors:

Errors ``` error[E0658]: `impl Trait` in associated types is unstable --> /home/alexander/Documents/dev/postcard-rpc/source/postcard-rpc/src/target_server/dispatch_macro.rs:446:5 | 446 | #[embassy_executor::task] | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #63063 for more information = help: add `#![feature(impl_trait_in_assoc_type)]` to the crate attributes to enable = note: this compiler was built on 2024-04-21; consider upgrading it if it is out of date = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0599]: no method named `wait_enabled` found for associated type `>::EndpointOut` in the current scope --> /home/alexander/Documents/dev/postcard-rpc/source/postcard-rpc/src/target_server/mod.rs:130:16 | 130 | ep_out.wait_enabled().await; | ^^^^^^^^^^^^ method not found in `>::EndpointOut` | ::: /home/alexander/.cargo/git/checkouts/embassy-9312dcb0ed774b29/e3e3728/embassy-usb-driver/src/lib.rs:227:14 | 227 | async fn wait_enabled(&mut self); | ------------ the method is available for `>::EndpointOut` here | = help: items from traits can only be used if the trait is in scope help: trait `Endpoint` which provides `wait_enabled` is implemented but not in scope; perhaps you want to import it | 3 + use embassy_usb::embassy_usb_driver::Endpoint; | error[E0599]: no method named `read` found for associated type `>::EndpointOut` in the current scope --> /home/alexander/Documents/dev/postcard-rpc/source/postcard-rpc/src/target_server/mod.rs:143:38 | 143 | match ep_out.read(rx_buf).await { | ^^^^ method not found in `>::EndpointOut` | ::: /home/alexander/.cargo/git/checkouts/embassy-9312dcb0ed774b29/e3e3728/embassy-usb-driver/src/lib.rs:236:14 | 236 | async fn read(&mut self, buf: &mut [u8]) -> Result; | ---- the method is available for `>::EndpointOut` here | = help: items from traits can only be used if the trait is in scope help: trait `EndpointOut` which provides `read` is implemented but not in scope; perhaps you want to import it | 3 + use embassy_usb::embassy_usb_driver::EndpointOut; | error[E0599]: no method named `read` found for associated type `>::EndpointOut` in the current scope --> /home/alexander/Documents/dev/postcard-rpc/source/postcard-rpc/src/target_server/mod.rs:163:38 | 163 | let n = match ep_out.read(window).await { | ^^^^ method not found in `>::EndpointOut` | ::: /home/alexander/.cargo/git/checkouts/embassy-9312dcb0ed774b29/e3e3728/embassy-usb-driver/src/lib.rs:236:14 | 236 | async fn read(&mut self, buf: &mut [u8]) -> Result; | ---- the method is available for `>::EndpointOut` here | = help: items from traits can only be used if the trait is in scope help: trait `EndpointOut` which provides `read` is implemented but not in scope; perhaps you want to import it | 3 + use embassy_usb::embassy_usb_driver::EndpointOut; | error[E0277]: the trait bound `::Driver: embassy_usb_driver::Driver<'static>` is not satisfied --> /home/alexander/Documents/dev/postcard-rpc/source/postcard-rpc/src/target_server/mod.rs:43:25 | 43 | fn sender(&self) -> Sender; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `embassy_usb_driver::Driver<'static>` is not implemented for `::Driver` | note: required by a bound in `sender::Sender` --> /home/alexander/Documents/dev/postcard-rpc/source/postcard-rpc/src/target_server/sender.rs:15:45 | 15 | pub struct Sender + 'static> { | ^^^^^^^^^^^^^^^ required by this bound in `Sender` help: consider further restricting the associated type | 43 | fn sender(&self) -> Sender where ::Driver: embassy_usb_driver::Driver<'static>; | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ error[E0277]: the trait bound `FakeDriver: embassy_usb::embassy_usb_driver::Driver<'static>` is not satisfied --> /home/alexander/Documents/dev/postcard-rpc/source/postcard-rpc/src/target_server/dispatch_macro.rs:410:64 | 410 | dispatcher: TestDispatcher; | ^^^^^^^^^^ the trait `embassy_usb::embassy_usb_driver::Driver<'static>` is not implemented for `FakeDriver` | note: required by a bound in `target_server::Dispatch::Driver` --> /home/alexander/Documents/dev/postcard-rpc/source/postcard-rpc/src/target_server/mod.rs:29:18 | 29 | type Driver: Driver<'static>; | ^^^^^^^^^^^^^^^ required by this bound in `Dispatch::Driver` error[E0277]: the trait bound `FakeDriver: embassy_usb::embassy_usb_driver::Driver<'static>` is not satisfied --> /home/alexander/Documents/dev/postcard-rpc/source/postcard-rpc/src/target_server/dispatch_macro.rs:118:24 | 118 | ep_in: <$driver as ::embassy_usb::driver::Driver<'static>>::EndpointIn, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `embassy_usb::embassy_usb_driver::Driver<'static>` is not implemented for `FakeDriver` ... 409 | / define_dispatch! { 410 | | dispatcher: TestDispatcher; 411 | | AlphaEndpoint => async test_alpha_handler, 412 | | BetaEndpoint => async test_beta_handler, ... | 415 | | EpsilonEndpoint => spawn test_epsilon_handler_task, 416 | | } | |_____- in this macro invocation | = note: this error originates in the macro `define_dispatch` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `FakeDriver: embassy_usb::embassy_usb_driver::Driver<'static>` is not satisfied --> /home/alexander/Documents/dev/postcard-rpc/source/postcard-rpc/src/target_server/dispatch_macro.rs:120:23 | 120 | ) -> Self { | _______________________^ 121 | | static SENDER_INNER: ::static_cell::StaticCell< 122 | | ::embassy_sync::mutex::Mutex<$mutex, $crate::target_server::sender::SenderInner<$driver>>, 123 | | > = ::static_cell::StaticCell::new(); ... | 127 | | } 128 | | } | |_____________^ the trait `embassy_usb::embassy_usb_driver::Driver<'static>` is not implemented for `FakeDriver` ... 409 | / define_dispatch! { 410 | | dispatcher: TestDispatcher; 411 | | AlphaEndpoint => async test_alpha_handler, 412 | | BetaEndpoint => async test_beta_handler, ... | 415 | | EpsilonEndpoint => spawn test_epsilon_handler_task, 416 | | } | |_____- in this macro invocation | = note: this error originates in the macro `define_dispatch` (in Nightly builds, run with -Z macro-backtrace for more info) warning: unused import: `EndpointOut` --> /home/alexander/Documents/dev/postcard-rpc/source/postcard-rpc/src/target_server/mod.rs:14:51 | 14 | use embassy_usb_driver::{Endpoint, EndpointError, EndpointOut}; | ^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: unused import: `Endpoint` --> /home/alexander/Documents/dev/postcard-rpc/source/postcard-rpc/src/target_server/mod.rs:14:26 | 14 | use embassy_usb_driver::{Endpoint, EndpointError, EndpointOut}; | ^^^^^^^^ Some errors have detailed explanations: E0277, E0599, E0658. For more information about an error, try `rustc --explain E0277`. warning: `postcard-rpc` (lib) generated 2 warnings error: could not compile `postcard-rpc` (lib) due to 8 previous errors; 2 warnings emitted warning: build failed, waiting for other jobs to finish... ```

I don't fully understand what the problem is but I figure this change is mostly harmless.

I also added the #![feature(impl_trait_in_assoc_type)] crate attribute to silence the error from the fake module. I'm not sure why I need this because I already have this attribute in my own crate root. It also makes this crate nightly-only which is probably not what you want. Alternatively the whole module could be guarded behind a feature flag.