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

Add a safe way to create UninitSlice from slices #598

Merged
merged 1 commit into from
Feb 9, 2023

Conversation

mina86
Copy link
Contributor

@mina86 mina86 commented 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.

Fixes: #552

src/buf/uninit_slice.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

Let's put #[inline] markers on them. Otherwise, it looks good.

src/buf/uninit_slice.rs Show resolved Hide resolved
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
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

Thanks.

@Darksonn Darksonn merged commit 99a2754 into tokio-rs:master Feb 9, 2023
@mina86 mina86 deleted the b branch February 9, 2023 17:15
@mina86
Copy link
Contributor Author

mina86 commented Feb 11, 2023

By the way, ReadBuf calls those new and uninit. As much as I hate ReadBuf, maybe it’s worth unifying naming with it?

@Darksonn
Copy link
Contributor

Ah, that could make sense.

@mina86
Copy link
Contributor Author

mina86 commented Feb 11, 2023

Hmm, then again, BorrowedBuf doesn’t have constructors at all and uses From trait. So maybe dropping those constructors would be even better? I have no preference here; wondering what would be best convention.

@Darksonn
Copy link
Contributor

No, I think it is good practice to have constructors.

@mina86
Copy link
Contributor Author

mina86 commented Feb 11, 2023

#599

@Darksonn Darksonn mentioned this pull request Sep 6, 2023
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.

Safe method for creating UninitSlice
2 participants