-
Notifications
You must be signed in to change notification settings - Fork 2
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
Expose the Backend Trait publicly #184
base: main
Are you sure you want to change the base?
Conversation
@marco-swz, unsealing the |
At the earlier stage of my project, sending fixed responses to messages was sufficient to test my program. Now that the main functionality is finished, I want to focus on better tests. It is not enough anymore to check the messages itself. I want to make sure the order of execution is correct and complicated edge cases are handled properly, potentially even going in the direction of simulation testing. Basically, I don't want to send fixed responses, but make them dependent on the internal state of the backend. Unfortunately, this is not possible with the Before the |
This doesn't sound trivial. It's also worth noting that long commands may be split across multiple packets, which your backend would need to merge together. Similarly, for replies longer than the maximum packet size, it would need to split them (see https://www.zaber.com/protocol-manual#topic_line_continuation for details).
Right, the signature of the callback in For instance it would let you do something like the following: let mut sim = MySimulatedDeviceChain::new();
let mut port = Port::open_mock();
port.backend_mut().set_write_callback(move |message, buffer| { sim.handle(message, buffer); }); I've gone ahead an implemented this in #185, as it's plainly better. Does that work for your use case?
I agree, for simple cases
This isn't possible, unfortunately, for multiple reasons. First, there is not single implementation that would be correct for all backends. Second, Regarding this change in general, I'm not opposed to exposing the |
Thanks for the info! Fortunately, I don't need to implement the entire functionality in my simulator, only the few commands I use in my program.
This is a great improvement, since Nevertheless, I will probably stay on my fork with public |
For testing purposes, I want to use
Port
with a custom simulator as backend. This would be as simple as implementing theBackend
trait for my simulator struct. Unfortunately,Backend
is currently not accessible outside the crate.This pull request removes the
Sealed
trait and consequently makesBackend
publicly accessible. Users can now implement their own backend and instantiate ports withPort::from_backend()
.Let me know what you think!