lkml.org 
[lkml]   [2023]   [Mar]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH v3 08/13] rust: init: add `stack_pin_init!` macro
From
On 3/30/23 13:06, Gary Guo wrote:
>> +impl<T> StackInit<T> {
>> + /// Creates a new [`StackInit<T>`] that is uninitialized. Use [`stack_pin_init`] instead of this
>> + /// primitive.
>> + ///
>> + /// [`stack_pin_init`]: kernel::stack_pin_init
>> + #[inline]
>> + pub fn uninit() -> Self {
>> + Self(MaybeUninit::uninit(), false)
>> + }
>> +
>> + /// Initializes the contents and returns the result.
>> + ///
>> + /// # Safety
>> + ///
>> + /// The caller ensures that `self` is on the stack and not accessible in any other way, if this
>> + /// function returns `Ok`.
>> + #[inline]
>> + pub unsafe fn init<E>(&mut self, init: impl PinInit<T, E>) -> Result<Pin<&mut T>, E> {
>
> Could this be made safe if the signature takes `self: Pin<&mut Self>`
> instead?
>
> The std `pin!` macro is stable in
> 1.68 so we can just `core::pin::pin!(StackInit::uninit())` and then
> call `init` on it.
>
> Best,
> Gary

Yeah, I think that would work. If it's marked safe, then it will be
possible to call `init` several times, but this is fine if `init`
transitions the `StackInit` back into its uninitialized state before
attempting to initialize it again.

\
 
 \ /
  Last update: 2023-03-30 17:08    [W:0.210 / U:0.264 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site