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

Better empty struct rust code gen #165

Merged
merged 1 commit into from
Dec 14, 2021
Merged

Better empty struct rust code gen #165

merged 1 commit into from
Dec 14, 2021

Conversation

mattiekat
Copy link
Contributor

Noticed rust was being a bit dumb on empty structs and it was an easy fix.

Before it would generate

fn _deserialize_chained(raw: &'raw [u8]) -> ::bebop::DeResult<(usize, Self)> {
    let mut i = 0;
    if raw.len() - i < Self::MIN_SERIALIZED_SIZE {
        let missing = Self::MIN_SERIALIZED_SIZE - (raw.len() - i);
        return Err(::bebop::DeserializeError::MoreDataExpected(missing));
    }

    Ok((i, Self {
    }))
}

Now it generates

fn _deserialize_chained(raw: &'raw [u8]) -> ::bebop::DeResult<(usize, Self)> {
    Ok((0, Self {}))
}

@mattiekat mattiekat requested a review from lynn December 14, 2021 22:12
@mattiekat mattiekat changed the title Better empty struct code gen Better empty struct rust code gen Dec 14, 2021
@mattiekat mattiekat merged commit b3e4d57 into master Dec 14, 2021
@mattiekat mattiekat deleted the empty-structs branch December 14, 2021 23:27
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.

None yet

2 participants