-
Notifications
You must be signed in to change notification settings - Fork 88
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
Proposal for a re-worked API #246
Comments
Ah I was planning to remove the length prefix in |
Cool! Yeah I am okay with it being removed. That isn't the only part of my proposal though so I am keen to hear your opinion on the remaining points :) |
Re: Suggestion 1Click to openAs far as I know, Re: Suggestion 2Click to openRewriting BytesWriterHmm, I assume the focus here is on improving the user interface (as opposed to making the library codebase smaller). If so, one way I can think of doing it is to rewrite So far, I don't think this is idealHowever, ultimately I don't think this is something we want to do; I'd have a few arguments in favor of the current system:
Having said that, I'm open to counterarguments! I'm not very experienced, so do let me know if I'm straight up not making sense haha 😅 Re: Suggestion 3Click to openI'm not familiar with It would be quite a big addition, so I probably won't have time to work on it myself; I'd welcome a PR though! If you do decide to pursue it, perhaps it would be ideal to open an issue / draft PR early on while working on it, so that other users can discuss their needs before investing large amounts of time in it. Out of curiosity, have you any thoughts on using Re: Suggestion 4Yep, I intend to submit a PR to remove the length prefixes soon. Re: Suggestion 5Click to openI'm not sure if I understand this suggestion correctly, but currently, the module root directly exposes:
If I'm not wrong, Meanwhile, Since a core focus of this library is on speed optimization, I would want to keep Re: Suggestion 6Sorry I'm not very sure what you mean by duplication; could you briefly clarify? |
Sorry for the late reply, this kind of went under the radar 😅
It is really about reducing the API surface for the user. All three traits are auto-generated, right? But all three have to imported when you want to interact with the generated code.
100%. I think the main APIs exposed to the user should be as simple as possible and serve the majority of use cases. Ideally, they only have to deal with concepts they are already familiar with, like
That would be ideal! :) Not sure how ergonomic the
It is mostly about following similar naming patterns and avoiding unnecessary "naming". If I am using fn main() {
let message = quick_protobuf::from_slice::<MyMessage>(&buf).unwrap();
}
Sure! But again, we should drop the |
We are in the process of adopting
quick-protobuf
inrust-libp2p
and a few points came up whilst using the API.MessageWrite::write_message
andWriter::write_message
. The latter uses the former but also includes a length-prefix. We've tripped over this multiple times.serialize_into_vec
which writes a length-prefix but it is not documented.BytesWriter
, aWriter
, aWriterBackend
and theMessageWrite
. The relationship is not entirely clear from the naming.My suggestions would be:
MessageInfo
,MessageRead
andMessageWrite
into a single traitMessage
.std::io::Write
. CanMessage::write
perhaps simply take a&mut std::io::Write
? This would remove the layer of constructing aWriter
with aWriterBackend
. Astd::fs::File
already implementsWrite
and so doesstd::vec::Vec
.AsyncMessage
type that uses thefutures
abstractionAsyncRead
andAsyncWrite
.quick_protobuf::from_slice::<M>(&[u8]) -> Result<M>
quick_protobuf::to_vec::<M>(M) -> Vec<u8>
serde
is a battle-tested library. We should be able to take some inspiration from what functions they provide: https://docs.rs/serde_json/1.0.93/serde_json/#functionscodegen
orinternal
which clearly signals to users that they shouldn't use these directly.Let me know what you think. I am open to working on this and sending PRs :)
The text was updated successfully, but these errors were encountered: