Re: [PATCH] rust: types: Make Opaque::get const

From: Alice Ryhl
Date: Tue Apr 02 2024 - 05:46:32 EST


On Mon, Apr 1, 2024 at 11:46 PM Boqun Feng <boqun.feng@xxxxxxxxx> wrote:
>
> To support a potential usage:
>
> static foo: Opaque<Foo> = ..; // Or defined in an extern block.
>
> ...
>
> fn bar() {
> let ptr = foo.get();
> }
>
> `Opaque::get` need to be `const`, otherwise compiler will complain
> because calls on statics are limited to const functions.
>
> Also `Opaque::get` should be naturally `const` since it's a composition
> of two `const` functions: `UnsafeCell::get` and `ptr::cast`.
>
> Signed-off-by: Boqun Feng <boqun.feng@xxxxxxxxx>

Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>