Skip to main content

Slot

Struct Slot 

Source
pub struct Slot<T> { /* private fields */ }
Expand description

A value of type T kept in a context’s temporary memory, by name.

Per context by default; Slot::keyed gives one value per key (a widget’s id, a viewport). Names are unique across egui-pop and the application, prefixed by the crate (core.slider.typing).

Implementations§

Source§

impl<T: Clone + Send + Sync + 'static> Slot<T>

Source

pub const fn new(name: &'static str) -> Self
where T: Debug,

A slot per context, its values summarised by their Debug form.

Source

pub const fn summarised(name: &'static str, summary: fn(&T) -> String) -> Self

A slot per context whose values say themselves what the debug bridge should read, when their Debug form would not fit in a summary.

Source

pub const fn opaque(name: &'static str) -> Self

A slot per context whose values have no Debug form (handles, trait objects): summarised by their type.

Source

pub fn keyed(self, key: impl Hash + Debug) -> Self

The same slot, one value per key (a widget’s id, a viewport).

Source

pub fn name(&self) -> &'static str

The slot’s name.

Source

pub fn scope(&self) -> Scope

Per context or per instance.

Source

pub fn id(&self) -> Id

The id the value is kept under in egui’s memory.

Source

pub fn get(&self, ctx: &Context) -> Option<T>

The value, cloned.

Source

pub fn get_or_default(&self, ctx: &Context) -> T
where T: Default,

The value, or T::default() (nothing is stored).

Source

pub fn exists(&self, ctx: &Context) -> bool

Whether a value is stored.

Source

pub fn set(&self, ctx: &Context, value: T)

Stores a value.

Source

pub fn remove(&self, ctx: &Context) -> Option<T>

Removes the value; what it was.

Source

pub fn get_or_insert_with(&self, ctx: &Context, make: impl FnOnce() -> T) -> T

The value, created by make when there is none. make runs outside egui’s lock: it may read the context.

Source

pub fn update<R>(&self, ctx: &Context, f: impl FnOnce(&mut T) -> R) -> R
where T: Default,

Changes the value in place (T::default() when there is none) and returns what f returns. f runs under egui’s lock: it must not touch the context (no ctx.viewport_id(), no other slot).

Trait Implementations§

Source§

impl<T> Clone for Slot<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Slot<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Copy for Slot<T>

Auto Trait Implementations§

§

impl<T> Freeze for Slot<T>

§

impl<T> RefUnwindSafe for Slot<T>

§

impl<T> Send for Slot<T>

§

impl<T> Sync for Slot<T>

§

impl<T> Unpin for Slot<T>

§

impl<T> UnsafeUnpin for Slot<T>

§

impl<T> UnwindSafe for Slot<T>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,