-
Notifications
You must be signed in to change notification settings - Fork 4
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
Remove generic arguments for read and write buffer. #21
base: main
Are you sure you want to change the base?
Conversation
I agree it is getting busy but losing the flexibility of a simple generic is a shame. It could be reduced down to one as I don't see a scenario where you would want the read and write buffer to be different types. Could just be Removing them would be even better, although I can't quite see a way for it to work without having a buffer somewhere. The message return size could be a const generic but that might further complicate things. And actually you can't calculate the exact |
I'm thinking that it might be possible to use a buffer on the stack whenever we actually perform a read or write. The stack buffer can be owned by the function that does the read/write. But we will not be able to return The other alternative is that you have to pass in a buffer as argument to all functions that need it (which is basically every function). That makes the API closer to raw socket calls, which is good for performance and flexibility, but bad for usability. One |
Is it possible to have different default generics for different |
Hmm, yeah, that should be possible. I like that, users wont normally be confronted with generics they don't care about, but if you do care you can still specify them. I'll rework this PR later! |
Could also make the SerialPort generic default on std? |
This one is a bit more difficult, because that means we need to have no default without the #[cfg(feature = "alloc")]
type DefaultBuffer = Vec<u8>;
#[cfg(not(feature = "alloc"))]
type DefaultBuffer = &'static mut [u8];
struct Client<SerialPort, Buffer = DefaultBuffer> {
...
} But removing the default based on lack of a feature means duplicating the struct definition. Still possible though, but slightly more risky.
Yeah, we have to consider what value most users will want to change. On I'm leaning towards putting the |
a3a08bb
to
79ab7da
Compare
Updated the PR. Now it:
|
79ab7da
to
33792e3
Compare
Yes I think this is a great solution and I love the way you have implemented it. Unfortunately, we will also have to do this for the |
Main goal is to reduce the mental overhead of using the
Client
andDevice
types. Having three generic types can be quite cumbersome to handle.Downside: this solution doesn't allow using owned fixed-size arrays as buffer anymore. The only way to use a simple fixed size array is by borrowing it or by boxing it (requires
feature = "alloc"
).@omelia-iliffe: Can you see what you think about this solution too?
/edit: Hmm, maybe the buffers can be totally removed from the struct... The only reason they need to be owned/borrowed by the bus is because one
serial_port.read()
could read multiple responses at once. But we usually discard all data before sending a new command.Only in the case of single command multiple response is this a real problem. But maybe the new iterator-like design for multi-response-instructions can keep the buffer borrowed until the last response is read...