1 // SPDX-License-Identifier: GPL-2.0
5 use core::{cell::UnsafeCell, mem::MaybeUninit};
7 /// Stores an opaque value.
9 /// This is meant to be used with FFI objects that are never interpreted by Rust code.
11 pub struct Opaque<T>(MaybeUninit<UnsafeCell<T>>);
14 /// Creates a new opaque value.
15 pub const fn new(value: T) -> Self {
16 Self(MaybeUninit::new(UnsafeCell::new(value)))
19 /// Creates an uninitialised value.
20 pub const fn uninit() -> Self {
21 Self(MaybeUninit::uninit())
24 /// Returns a raw pointer to the opaque data.
25 pub fn get(&self) -> *mut T {
26 UnsafeCell::raw_get(self.0.as_ptr())
30 /// A sum type that always holds either a value of type `L` or `R`.
31 pub enum Either<L, R> {
32 /// Constructs an instance of [`Either`] containing a value of type `L`.
35 /// Constructs an instance of [`Either`] containing a value of type `R`.