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

Adding float support, DecodeOwned array blanket implementation #2

Merged
merged 2 commits into from
Nov 23, 2022

Conversation

ryan-summers
Copy link
Contributor

This PR fixes #1 by adding f32/f64 support for Enc/Dec traits.

@ryan-summers ryan-summers changed the title Adding float support Adding float support, DecodeOwned array blanket implementation Nov 21, 2022
type Output = [<T as DecodeOwned>::Output; N];

fn decode_owned(buff: &[u8]) -> Result<(Self::Output, usize), Self::Error> {
let mut data: [T; N] = [T::default(); N];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd really love to use MaybeUninit for this, but I couldn't get it to work. Making an [MaybeUninit::uninit(); N] requires a T: Copy, and then attempting to core::mem::transmute() the MaybeUninit into a [T; N] results in a compiler error due to sizing issues for some reason, which appears to be a limitation of rust.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeeah, i fell down this rabbit hole too 😅 seems like a good enough approach for now, which can be removed once array::try_from_fn lands anyway

@ryankurte ryankurte merged commit 4437822 into ryankurte:main Nov 23, 2022
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.

Support for floating point values
2 participants