-
Notifications
You must be signed in to change notification settings - Fork 133
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 try_push_uninit and test #278
Conversation
/// | ||
/// This is useful if the backed value is large and won't fit on stack. | ||
/// | ||
/// Capacity error carries the data - since we don't have data then we need a different error type. |
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.
please use CapacityError<()>
Something like this is needed, but unsure about the right API |
/// This is useful if the backed value is large and won't fit on stack. | ||
/// | ||
/// Capacity error carries the data - since we don't have data then we need a different error type. | ||
pub unsafe fn try_push_uninit(&mut self) -> Result<*mut T, ()> { |
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.
Let's use a NonNull<T>
for the pointer. While we think of the best shape of API for this.
let field_two = unsafe {&mut (*ptr).field_two}; | ||
*field_two = [2; 1_000_000]; | ||
let field_three = unsafe {&mut (*ptr).field_three}; | ||
*field_three = [3; 1_000_000]; |
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.
Raw pointer is not a good interface because the user needs to remember to use field_three.write(...)
. Assigning with *field_three = ...
only works for Copy types. The point is that the assignment first drops the existing value before copying (nominally) the new value into its place. MaybeUninit is a good place to look.
Perhaps this could take the same shape as |
@tbu- that sounds good! |
This mirrors `Vec::spare_capacity_mut`. Description and example are taken from this function, too. CC bluss#278
This mirrors `Vec::spare_capacity_mut`. Description and example are taken from this function, too. CC bluss#278
This mirrors `Vec::spare_capacity_mut`. Description and example are taken from this function, too. CC bluss#278
This mirrors `Vec::spare_capacity_mut`. Description and example are taken from this function, too. CC #278
Add try_push_uninit , which tries to add an additional element and provides a raw pointer to the already allocated memory.
This is useful if the backing structure is larger than the stack size.
Included is a test that demonstrates the need for this functionality.