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>
impl<T> GILOnceCell<T>
Sourcepub fn get(&self, _py: Python<'_>) -> Option<&T>
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.
Sourcepub fn get_or_try_init<F, E>(&self, py: Python<'_>, f: F) -> Result<&T, E>
pub fn get_or_try_init<F, E>(&self, py: Python<'_>, f: F) -> 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.
fn init<F, E>(&self, py: Python<'_>, f: F) -> Result<&T, E>
Trait Implementationsยง
Sourceยงimpl<T> Default for GILOnceCell<T>
impl<T> Default for GILOnceCell<T>
Sourceยงimpl<T> Drop for GILOnceCell<T>
impl<T> Drop for GILOnceCell<T>
impl<T: Send> Send for GILOnceCell<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSourceยงimpl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Sourceยง#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
๐ฌThis is a nightly-only experimental API. (
sized_type_properties)Sourceยง#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
๐ฌThis is a nightly-only experimental API. (
sized_type_properties)Sourceยง#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
๐ฌThis is a nightly-only experimental API. (
ptr_alignment_type)Sourceยง#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
๐ฌThis is a nightly-only experimental API. (
sized_type_properties)Sourceยง#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
๐ฌThis is a nightly-only experimental API. (
sized_type_properties)Sourceยง#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[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