-
Notifications
You must be signed in to change notification settings - Fork 97
rust: release cleanup #1071
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
rust: release cleanup #1071
Conversation
907492f to
306afa1
Compare
2fd8aec to
3f21635
Compare
| @@ -0,0 +1,210 @@ | |||
| //! Functionality for parsing/writing SBP message payloads with in memory buffers | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some actual new-ish code. A combination of SbpSerialize and all the free standing parse_<type>() functions
| } | ||
| } | ||
|
|
||
| fn parse_unchecked(buf: &mut BytesMut) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably a premature optimization. But, this is pretty much the example right out of the docs for MaybeUninit so I don't feel too bad about this touch of unsafe
| @@ -0,0 +1,229 @@ | |||
| use std::fmt; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other chunk of actually new stuff
Semantics look a lot better, but I think we'd need further changes for this to have a real impact on (potential) heap fragmentation issues. "Further changes" would probably mean the ability to allocate the whole SBP message struct on the stack with variable sized arrays backed by an "upper maximum" static array (similar to the new v4 libsbp API for C). I tried to make a change to ensure that we're allocating consistently size buffers here: 64cafc3 to make things easier for heap reclamation -- but it did not have any impact on the specific console issue (which probably means it's just a leak, not a fragmentation issue). |
silverjam
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New code looks good
jbangelo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good to me.
| use self::unknown::Unknown; | ||
|
|
||
| use crate::serialize::SbpSerialize; | ||
| mod lib { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be called a prelude? Or is that term just for common imports from an external crate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm yeah I just took the idea from serde_json where they call it lib - https://docs.serde.rs/src/serde_json/lib.rs.html#366
Although they are doing it for a slightly different reason (still internal though)
| pub trait ConcreteMessage: SbpMessage + std::convert::TryFrom<Sbp, Error = TryFromSbpError> + Clone + Sized { | ||
| /// Implemented by messages who's message name and type are known at compile time. | ||
| /// This is everything that implements [SbpMessage] except for [Sbp]. | ||
| pub trait ConcreteMessage: SbpMessage + TryFrom<Sbp, Error = TryFromSbpError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If ConcreteMessage is only for use in the sbp crate, should this be marked as pub(crate)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm it can't be marked private because it a appears in Event which needs to be public. Could maybe add #[doc(hidden)]. Depends on if we think having access to message names/ids at compile time is useful. Right now this is the only way to get that
| _ => panic!("Invalid message type! Expected a (((t.msg.name)))"), | ||
| }; | ||
| let frame = sbp_msg.to_frame().unwrap(); | ||
| let frame = sbp::to_vec(&sbp_msg).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit. What is the idiomatic rule of thumb for using to_asdf vs as_asdf? Is it related to the cost of the action such as a string to slice using "as" vs a vector to string use "to"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah pretty much - as_ should be cheap and not consume the original. to_ can be more expensive and still does not consume the original. Then into_ can be either I guess but it should consume the original value. So in this case I went with to_ because it allocates
| s = s.replace(url, "<" + url + ">") | ||
| return s | ||
|
|
||
| def escape_braces(s): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe for a future addition, it would be neat to see if we could somehow get python docstrings embedded into the rust generated docs seeing as how these are related to the crate generation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah kind of like how the top of each message file tells you which yaml file it came from
Apologies in advance for the massive diff. Most of it is renaming/moving things around. The bulk of new changes are in
wire_format.rsandsbp_string.rs.Breaking API changes:
get_prefix from getters - https://rust-lang.github.io/api-guidelines/naming.html#getter-names-follow-rust-convention-c-getterSBP->SbpandSBPMessage->SbpMessage. Also treats acronyms like GPS/NED as one word (i.e. Gps/Ned) - https://rust-lang.github.io/api-guidelines/naming.html#casing-conforms-to-rfc-430-c-case. The casing of JSON messages was left as issbp_serdefeature to justserde- https://rust-lang.github.io/api-guidelines/naming.html?highlight=fea#feature-names-are-free-of-placeholder-words-c-featureErrorenum with two,DeserializeError/SerializeError. The finer grained types prevent you from having to deal with errors that can never happen#[non_exhaustive](not that anyone is realistically matching on all variants but you never know)dencode/bytes. Reading messages is done viaiter_messageslike before. Writing messages now can be done withsbp::to_writerorsbp::to_vec.SbpEncoderis available for writing messages with buffered output. Previously you needed to usedencode::FramedWritewith the encoder, but now each encoder contains theFramedWriteSBPTools->SbpIterExtbecause that's what it is/that's normally what I see things like this calledAdditions:
[f64; 3]not aVec<f64>Internal improvements:
<link>#[allow(..)]statements in the generated code by tweaking the code gennom/thiserror/byteorder. Without any features enabled we dropped from 46 deps to 10, debug builds drop from ~22 -> ~9 seconds and release builds from ~43 -> ~11 seconds. It turns outbyteshas all we need for parsing (mainly an easy way to pull LE bytes out of a buffer).SbpSerializetrait and replaces it withWireFormat(not sure this is the best name). It's very similar to SbpSerialize but also includes functions for reading the types. UnlikeSbpSerializethis trait is not public. Well it's technically public but unnameable by downstream crates (https://rust-lang.github.io/api-guidelines/future-proofing.html). This was done because it's really an implementation detail. Plus, becauseWireFormatis a super trait ofSbpMessage, it makes it impossible for downstream crates to implementSbpMessagewhich is probably a good idea.Future things:
All in all a lot of changes. Happy to undo any of them that people don't like/think are unnecessary