-
Notifications
You must be signed in to change notification settings - Fork 112
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
Provide a method to allocate a slice of zeroed/default values #41
Comments
@fitzgen I can do a PR if you think that this addition makes sense. |
Can you sketch the API / method signature you're looking for here? Zeroing memory is not going to result in a safe API in the general case (hence |
Something like fn alloc_slice_fill_copy<T: Copy>(&self, len: usize, value: &T) -> &mut [T];
fn alloc_slice_fill_clone<T: Clone>(&self, len: usize, value: &T) -> &mut [T];
fn alloc_slice_fill_default<T: Default>(&self, len: usize) -> &mut [T]; Basically the equivalent of
Yeah, I don't need zeroed memory in particular, but slice with default values. It was just that I had integer types in mind when I created the issue. |
That looks great -- happy to take a PR implementing those APIs! |
I believe this is fully implemted now. If I'm mistaken, please re-open! |
Thanks! @fitzgen It would be great if you could cut a release with this feature! |
See #51 |
Currently to bump-allocate any slice an existing slice is needed which is not always convenient. I guess currently the workaround is to use the
alloc_layout
method, but a method that doesn't requireunsafe
would be handy. Another handy addition would be a method that allocates and fills a slice with copies/clones of a single value.The text was updated successfully, but these errors were encountered: