-
Notifications
You must be signed in to change notification settings - Fork 74
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 support for arbritrary arrays #55
Conversation
I would prefer not to have nightly-only features in this crate. |
@fitzgen You might have a better insight but I am betting on 1.49 that is going to be released on 2020-12-31 |
I don't have any insider insight here, but I'd prefer revisiting after it merges to stable. Happy to leave this PR open until then. |
The time has come. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, modulo a couple nitpicks below. Fix those up and then we can merge this! Thanks @c410-f3r!
src/lib.rs
Outdated
{ | ||
let mut array: mem::MaybeUninit<[T; N]> = mem::MaybeUninit::uninit(); | ||
let mut guard: ArrayGuard<T, N> = ArrayGuard { | ||
dst: array.as_mut_ptr() as _, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the as
cast doing here? Converting from *mut [T; N]
to *mut T
? If so, can we lift that to multiple let
s that show the types, like this:
let dst: *mut [T; N] = array.as_mut_ptr();
let dst: *mut T = dst as _;
// ...
fn arbitrary_take_rest(mut u: Unstructured<'a>) -> Result<[T; $n]> { | ||
$(let $as = $ts::arbitrary(&mut u)?;)* | ||
let last = Arbitrary::arbitrary_take_rest(u)?; | ||
struct ArrayGuard<T, const N: usize> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a little documentation for what role this guard plays? That will help future readers of this code.
src/lib.rs
Outdated
{ | ||
let mut array: mem::MaybeUninit<[T; N]> = mem::MaybeUninit::uninit(); | ||
let mut guard: ArrayGuard<T, N> = ArrayGuard { | ||
dst: array.as_mut_ptr() as _, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto regarding the as
here.
Done. Thanks for the review |
Thanks! |
T: Default
would remove allunsafe
s but it isn't currently possible for[T; N]
and this bound limitation isn't desirable for stuff that don't implementDefault
.If rust-lang/rust#75644 is going to be accepted, then the auxiliary functions won't be necessary in the near future.