Skip to content
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 RawPacket and use slice instead #31

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

akumaigorodski
Copy link
Contributor

Here's my issue with RawPacket in the following example:

if let Some((Ok(raw_packet), _)) = parser.push_bytes_raw(out_buffer) {
    if let Ok(Packet::RcChannelsPacked(rc)) = Packet::parse(raw_packet) { // RawPacket gets moved here
        // we got specifically RC packet, do stuff
    }
    
    // forward RawPacket to flight controller anyway, whatever it happens to be
    // but we can not because it has been moved
    fc_port.write(raw_packet)
}

So, why don't we just drop it altogether and work with slices everywhere? In that case the code above just works without any changes. We will only lose a bit of semantic meaning, but arguably not much.

@akumaigorodski akumaigorodski marked this pull request as draft January 19, 2025 11:18
@tact1m4n3
Copy link
Owner

The good thing with RawPacket is it guarantees that the packet is valid (it can only be created by a parser). I don't really like using a slice instead. We could #[derive(Clone, Copy)] the RawPacket as an alternative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants