Re: [PATCH] rust: types: Make Opaque::get const
From: Wedson Almeida Filho
Date: Mon Apr 01 2024 - 19:22:05 EST
On Mon, 1 Apr 2024 at 18:46, 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: Wedson Almeida Filho <walmeida@xxxxxxxxxxxxx>