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 00:33, y86-dev@protonmail.com wrote:
> From: Benno Lossin <y86-dev@protonmail.com>
>
> The `stack_pin_init!` macro allows pin-initializing a value on the
> stack. It accepts a `impl PinInit<T, E>` to initialize a `T`. It allows
> propagating any errors via `?` or handling it normally via `match`.
>
> Signed-off-by: Benno Lossin <y86-dev@protonmail.com>

Reviewed-by: Alice Ryhl <aliceryhl@google.com>

> ---
> +#[macro_export]
> +macro_rules! stack_pin_init {
> + (let $var:ident $(: $t:ty)? = $val:expr) => {
> + let mut $var = $crate::init::__internal::StackInit$(::<$t>)?::uninit();
> + let mut $var = {
> + let val = $val;
> + unsafe { $crate::init::__internal::StackInit::init(&mut $var, val) }
> + };
> + };
> + (let $var:ident $(: $t:ty)? =? $val:expr) => {
> + let mut $var = $crate::init::__internal::StackInit$(::<$t>)?::uninit();
> + let mut $var = {
> + let val = $val;
> + unsafe { $crate::init::__internal::StackInit::init(&mut $var, val)? }
> + };
> + };
> +}

This will be inconvenient to use if the initializer is infallible and is
used inside an infallible function. However, I'm not sure what a better
alternative would be. Perhaps we should have three variants?

Also, maybe a `<-` rather than `=` would be more consistent?

Anyway, I don't think this should block the PR. We can revisit it later
if it becomes a problem.

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