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

Safe method for creating UninitSlice #552

Closed
Rossterd opened this issue Jul 4, 2022 · 1 comment · Fixed by #598
Closed

Safe method for creating UninitSlice #552

Rossterd opened this issue Jul 4, 2022 · 1 comment · Fixed by #598

Comments

@Rossterd
Copy link

Rossterd commented Jul 4, 2022

When implementing BufMut the BufMut::chunk_mut method requires you to return an UninitSlice instance.
As UninitSlice only has the unsafe from_raw_parts() constructor, this means that even if your slice is definitely already initiated you still need to write unsafe code to return this slice.

This isn't great, and it would be nice to have a way to safely create a UninitSlice from a slice of already initiated data.

@Darksonn
Copy link
Contributor

Darksonn commented Jul 5, 2022

Adding this seems fine to me.

mina86 added a commit to mina86/bytes that referenced this issue Feb 9, 2023
Introduce UninitSlice::from_slice_mut and UninitSlice::from_init_mut
methods which safely create Uninit slice from provided slice of maybe
uninitialised or initialised memory.

In addition, add `From<&mut [T]>` implementations (for `T=u8` and
`T=MaybeUninit<u8>`) which do conversion from slice to UninitSlice.

Closes: tokio-rs#552
mina86 added a commit to mina86/bytes that referenced this issue Feb 9, 2023
Introduce UninitSlice::from_slice and UninitSlice::from_uninit_slice
methods which safely create Uninit slice from provided slice of maybe
uninitialised or initialised memory.

In addition, add `From<&mut [T]>` implementations (for `T=u8` and
`T=MaybeUninit<u8>`) which do conversion from slice to UninitSlice.

Closes: tokio-rs#552
mina86 added a commit to mina86/bytes that referenced this issue Feb 9, 2023
Introduce UninitSlice::from_slice and UninitSlice::from_uninit_slice
methods which safely create Uninit slice from provided slice of maybe
uninitialised or initialised memory.

In addition, add `From<&mut [T]>` implementations (for `T=u8` and
`T=MaybeUninit<u8>`) which do conversion from slice to UninitSlice.

Closes: tokio-rs#552
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 a pull request may close this issue.

2 participants