Skip to main content

GILOnceCell

Struct GILOnceCell 

Source
pub(crate) struct GILOnceCell<T> {
    once: Once,
    data: UnsafeCell<MaybeUninit<T>>,
    _marker: PhantomData<T>,
}
๐Ÿ‘ŽDeprecated since 0.26.0:

Now internal only, to be removed after https://github.com/PyO3/pyo3/pull/5341

Fieldsยง

ยงonce: Once
๐Ÿ‘ŽDeprecated since 0.26.0:

Now internal only, to be removed after https://github.com/PyO3/pyo3/pull/5341

ยงdata: UnsafeCell<MaybeUninit<T>>
๐Ÿ‘ŽDeprecated since 0.26.0:

Now internal only, to be removed after https://github.com/PyO3/pyo3/pull/5341

ยง_marker: PhantomData<T>
๐Ÿ‘ŽDeprecated since 0.26.0:

Now internal only, to be removed after https://github.com/PyO3/pyo3/pull/5341

(Copied from std::sync::OnceLock)

PhantomData to make sure dropck understands weโ€™re dropping T in our Drop impl.

#![allow(deprecated)]
use pyo3::Python;
use pyo3::sync::GILOnceCell;

struct A<'a>(#[allow(dead_code)] &'a str);

impl<'a> Drop for A<'a> {
    fn drop(&mut self) {}
}

let cell = GILOnceCell::new();
{
    let s = String::new();
    let _ = Python::attach(|py| cell.set(py,A(&s)));
}

Implementationsยง

Sourceยง

impl<T> GILOnceCell<T>

Source

pub const fn new() -> Self

Create a GILOnceCell which does not yet contain a value.

Source

pub fn get(&self, _py: Python<'_>) -> Option<&T>

Get a reference to the contained value, or None if the cell has not yet been written.

Source

pub fn get_or_try_init<F, E>(&self, py: Python<'_>, f: F) -> Result<&T, E>
where F: FnOnce() -> Result<T, E>,

Like get_or_init, but accepts a fallible initialization function. If it fails, the cell is left uninitialized.

See the type-level documentation for detail on re-entrancy and concurrent initialization.

Source

fn init<F, E>(&self, py: Python<'_>, f: F) -> Result<&T, E>
where F: FnOnce() -> Result<T, E>,

Source

pub fn set(&self, _py: Python<'_>, value: T) -> Result<(), T>

Set the value in the cell.

If the cell has already been written, Err(value) will be returned containing the new value which was not written.

Trait Implementationsยง

Sourceยง

impl<T> Default for GILOnceCell<T>

Sourceยง

fn default() -> Self

Returns the โ€œdefault valueโ€ for a type. Read more
Sourceยง

impl<T> Drop for GILOnceCell<T>

Sourceยง

fn drop(&mut self)

Executes the destructor for this type. Read more
Sourceยง

impl<T: Send> Send for GILOnceCell<T>

Sourceยง

impl<T: Send + Sync> Sync for GILOnceCell<T>

Auto Trait Implementationsยง

ยง

impl<T> !Freeze for GILOnceCell<T>

ยง

impl<T> !RefUnwindSafe for GILOnceCell<T>

ยง

impl<T> Unpin for GILOnceCell<T>
where T: Unpin,

ยง

impl<T> UnsafeUnpin for GILOnceCell<T>
where T: UnsafeUnpin,

ยง

impl<T> UnwindSafe for GILOnceCell<T>
where T: UnwindSafe,

Blanket Implementationsยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<T> IntoEither for T

Sourceยง

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Sourceยง

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Sourceยง

impl<T> SizedTypeProperties for T

Sourceยง

#[doc(hidden)]
const SIZE: usize = _

๐Ÿ”ฌThis is a nightly-only experimental API. (sized_type_properties)
Sourceยง

#[doc(hidden)]
const ALIGN: usize = _

๐Ÿ”ฌThis is a nightly-only experimental API. (sized_type_properties)
Sourceยง

#[doc(hidden)]
const ALIGNMENT: Alignment = _

๐Ÿ”ฌThis is a nightly-only experimental API. (ptr_alignment_type)
Sourceยง

#[doc(hidden)]
const IS_ZST: bool = _

๐Ÿ”ฌThis is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Sourceยง

#[doc(hidden)]
const LAYOUT: Layout = _

๐Ÿ”ฌThis is a nightly-only experimental API. (sized_type_properties)
Sourceยง

#[doc(hidden)]
const MAX_SLICE_LEN: usize = _

๐Ÿ”ฌThis is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. Read more
Sourceยง

impl<T> SomeWrap<T> for T

Sourceยง

fn wrap(self) -> Option<T>

Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = Infallible

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Sourceยง

impl<T> Ungil for T
where T: Send,

โš ๏ธ Internal Docs โš ๏ธ Not Public API ๐Ÿ‘‰ Official Docs Here