Entity

Struct Entity 

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

A strong, well-typed reference to a struct which is managed by GPUI

Implementations§

Source§

impl<T: 'static> Entity<T>

Source

pub fn entity_id(&self) -> EntityId

Get the entity ID associated with this entity

Source

pub fn downgrade(&self) -> WeakEntity<T>

Downgrade this entity pointer to a non-retaining weak pointer

Source

pub fn into_any(self) -> AnyEntity

Convert this into a dynamically typed entity.

Source

pub fn read<'a>(&self, cx: &'a App) -> &'a T

Grab a reference to this entity from the context.

Source

pub fn read_with<R, C: AppContext>( &self, cx: &C, f: impl FnOnce(&T, &App) -> R, ) -> C::Result<R>

Read the entity referenced by this handle with the given function.

Source

pub fn update<R, C: AppContext>( &self, cx: &mut C, update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R, ) -> C::Result<R>

Updates the entity referenced by this handle with the given function.

Source

pub fn as_mut<'a, C: AppContext>( &self, cx: &'a mut C, ) -> C::Result<GpuiBorrow<'a, T>>

Updates the entity referenced by this handle with the given function.

Source

pub fn write<C: AppContext>(&self, cx: &mut C, value: T) -> C::Result<()>

Updates the entity referenced by this handle with the given function.

Source

pub fn update_in<R, C: VisualContext>( &self, cx: &mut C, update: impl FnOnce(&mut T, &mut Window, &mut Context<'_, T>) -> R, ) -> C::Result<R>

Updates the entity referenced by this handle with the given function if the referenced entity still exists, within a visual context that has a window. Returns an error if the entity has been released.

Methods from Deref<Target = AnyEntity>§

Source

pub fn entity_id(&self) -> EntityId

Returns the id associated with this entity.

Source

pub fn entity_type(&self) -> TypeId

Returns the TypeId associated with this entity.

Source

pub fn downgrade(&self) -> AnyWeakEntity

Converts this entity handle into a weak variant, which does not prevent it from being released.

Trait Implementations§

Source§

impl<T> Clone for Entity<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 Entity<T>

Source§

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

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

impl<T> Deref for Entity<T>

Source§

type Target = AnyEntity

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T> DerefMut for Entity<T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<V: Render> Element for Entity<V>

Source§

type RequestLayoutState = AnyElement

The type of state returned from Element::request_layout. A mutable reference to this state is subsequently provided to Element::prepaint and Element::paint.
Source§

type PrepaintState = ()

The type of state returned from Element::prepaint. A mutable reference to this state is subsequently provided to Element::paint.
Source§

fn id(&self) -> Option<ElementId>

If this element has a unique identifier, return it here. This is used to track elements across frames, and will cause a GlobalElementId to be passed to the request_layout, prepaint, and paint methods. Read more
Source§

fn source_location(&self) -> Option<&'static Location<'static>>

Source location where this element was constructed, used to disambiguate elements in the inspector and navigate to their source code.
Source§

fn request_layout( &mut self, _id: Option<&GlobalElementId>, _inspector_id: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, Self::RequestLayoutState)

Before an element can be painted, we need to know where it’s going to be and how big it is. Use this method to request a layout from Taffy and initialize the element’s state.
Source§

fn prepaint( &mut self, _id: Option<&GlobalElementId>, _inspector_id: Option<&InspectorElementId>, _: Bounds<Pixels>, element: &mut Self::RequestLayoutState, window: &mut Window, cx: &mut App, )

After laying out an element, we need to commit its bounds to the current frame for hitbox purposes. The state argument is the same state that was returned from Element::request_layout().
Source§

fn paint( &mut self, _id: Option<&GlobalElementId>, _inspector_id: Option<&InspectorElementId>, _: Bounds<Pixels>, element: &mut Self::RequestLayoutState, _: &mut Self::PrepaintState, window: &mut Window, cx: &mut App, )

Once layout has been completed, this method will be called to paint the element to the screen. The state argument is the same state that was returned from Element::request_layout().
Source§

fn into_any(self) -> AnyElement

Convert this element into a dynamically-typed AnyElement.
Source§

impl<V: Focusable> Focusable for Entity<V>

Source§

fn focus_handle(&self, cx: &App) -> FocusHandle

Returns the focus handle associated with this view.
Source§

impl<I: ImageCache> From<Entity<I>> for AnyImageCache

Source§

fn from(image_cache: Entity<I>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Entity<T>> for AnyEntity

Source§

fn from(entity: Entity<T>) -> Self

Converts to this type from the input type.
Source§

impl<V: Render> From<Entity<V>> for AnyView

Source§

fn from(value: Entity<V>) -> Self

Converts to this type from the input type.
Source§

impl<T> Hash for Entity<T>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: ImageCache> ImageCacheProvider for Entity<T>

Source§

fn provide(&mut self, _window: &mut Window, _cx: &mut App) -> AnyImageCache

Called during the request_layout phase to create an ImageCache.
Source§

impl<V: 'static + Render> IntoElement for Entity<V>

Source§

type Element = Entity<V>

The specific type of element into which the implementing type is converted. Useful for converting other types into elements automatically, like Strings
Source§

fn into_element(self) -> Self::Element

Convert self into a type that implements Element.
Source§

fn into_any_element(self) -> AnyElement

Convert self into a dynamically-typed AnyElement.
Source§

impl<T: 'static> Ord for Entity<T>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T> PartialEq<Entity<T>> for WeakEntity<T>

Source§

fn eq(&self, other: &Entity<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialEq<WeakEntity<T>> for Entity<T>

Source§

fn eq(&self, other: &WeakEntity<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialEq for Entity<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: 'static> PartialOrd for Entity<T>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: UniformListDecoration + 'static> UniformListDecoration for Entity<T>

Source§

fn compute( &self, visible_range: Range<usize>, bounds: Bounds<Pixels>, scroll_offset: Point<Pixels>, item_height: Pixels, item_count: usize, window: &mut Window, cx: &mut App, ) -> AnyElement

Compute the decoration element, given the visible range of list items, the bounds of the list, and the height of each item.
Source§

impl<T> Eq for Entity<T>

Auto Trait Implementations§

§

impl<T> Freeze for Entity<T>

§

impl<T> !RefUnwindSafe for Entity<T>

§

impl<T> Send for Entity<T>

§

impl<T> Sync for Entity<T>

§

impl<T> Unpin for Entity<T>

§

impl<T> !UnwindSafe for Entity<T>

Blanket Implementations§

Source§

impl<E> AnimationExt for E
where E: IntoElement + 'static,

Source§

fn with_animation( self, id: impl Into<ElementId>, animation: Animation, animator: impl Fn(Self, f32) -> Self + 'static, ) -> AnimationElement<Self>
where Self: Sized,

Render this component or element with an animation
Source§

fn with_animations( self, id: impl Into<ElementId>, animations: Vec<Animation>, animator: impl Fn(Self, usize, f32) -> Self + 'static, ) -> AnimationElement<Self>
where Self: Sized,

Render this component or element with a chain of animations
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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> FluentBuilder for T
where T: IntoElement,

Source§

fn map<U>(self, f: impl FnOnce(Self) -> U) -> U
where Self: Sized,

Imperatively modify self with the given closure.
Source§

fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
where Self: Sized,

Conditionally modify self with the given closure.
Source§

fn when_else( self, condition: bool, then: impl FnOnce(Self) -> Self, else_fn: impl FnOnce(Self) -> Self, ) -> Self
where Self: Sized,

Conditionally modify self with the given closure.
Source§

fn when_some<T>( self, option: Option<T>, then: impl FnOnce(Self, T) -> Self, ) -> Self
where Self: Sized,

Conditionally unwrap and modify self with the given closure, if the given option is Some.
Source§

fn when_none<T>( self, option: &Option<T>, then: impl FnOnce(Self) -> Self, ) -> Self
where Self: Sized,

Conditionally unwrap and modify self with the given closure, if the given option is None.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<K> MapSeekTarget<K> for K
where K: Ord,

Source§

fn cmp_cursor(&self, cursor_location: &K) -> Ordering

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more