pub trait Capsule: Send + 'static {
type Data: Send + Sync + 'static;
// Required methods
fn build(&self, handle: CapsuleHandle<'_, '_, '_>) -> Self::Data;
fn eq(old: &Self::Data, new: &Self::Data) -> bool;
// Provided method
fn key(&self) -> impl CapsuleKey { ... }
}
Expand description
Capsules are blueprints for creating some immutable data and do not actually contain any data themselves. See the documentation for more.
Required Associated Types§
Sourcetype Data: Send + Sync + 'static
type Data: Send + Sync + 'static
The type of data associated with this capsule, which must be Send + Sync + 'static
.
Capsule::Data
that implements Clone
will also unlock a few convenience methods.
Note: when your types do implement Clone
, it is suggested to be a “cheap” Clone.
Arc
s, small collections/data structures, and the im
crate are great for this.
Required Methods§
Sourcefn build(&self, handle: CapsuleHandle<'_, '_, '_>) -> Self::Data
fn build(&self, handle: CapsuleHandle<'_, '_, '_>) -> Self::Data
Builds the capsule’s immutable data using a given snapshot of the data flow graph.
(The snapshot, a ContainerWriteTxn
, is abstracted away for you via CapsuleHandle
.)
§Concurrency
ABSOLUTELY DO NOT TRIGGER ANY REBUILDS WITHIN THIS FUNCTION! Doing so may result in a deadlock or a panic.
Provided Methods§
Sourcefn key(&self) -> impl CapsuleKey
fn key(&self) -> impl CapsuleKey
Returns the key to use for this capsule. Most capsules should use the default implementation, which is for static capsules. If you specifically need dynamic capsules, such as for an incremental computation focused application, you will need to implement this function and return your capsule’s key.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.