[][src]Trait kompact::component::AbstractComponent

pub trait AbstractComponent: ActorRefFactory + CoreContainer + Any {
    fn dyn_definition_mut(
        &mut self
    ) -> &mut dyn DynamicComponentDefinition<Message = Self::Message>;
fn lock_dyn_definition(
        &self
    ) -> Result<DynamicComponentDefinitionMutexGuard<'_, Self::Message>, LockPoisoned>;
fn as_any(&self) -> &dyn Any; }

An object-safe trait that exposes most of functionality of a Component that isn't dependent on a particular ComponentDefinition.

Useful if you want to reduce code bloat by removing the generic parameter from Component<CD>.

See also: ActorRefFactory and CoreContainer, which this trait inherits.

Required methods

fn dyn_definition_mut(
    &mut self
) -> &mut dyn DynamicComponentDefinition<Message = Self::Message>

Returns a mutable reference to the underlying component definition as a DynamicComponentDefinition trait object.

This can only be done if you have a reference to the component instance that isn't hidden behind an Arc. For example, after the system shuts down and your code holds on to the last reference to a component you can use get_mut or try_unwrap.

fn lock_dyn_definition(
    &self
) -> Result<DynamicComponentDefinitionMutexGuard<'_, Self::Message>, LockPoisoned>

Locks the component definition mutex and returns a guard that can be dereferenced to access a DynamicComponentDefinition trait object.

fn as_any(&self) -> &dyn Any

Views self as Any. Can be used to downcast to a concrete Component.

Loading content...

Implementations

impl<M: MessageBounds> dyn AbstractComponent<Message = M>[src]

pub fn on_dyn_definition<F, R>(&self, f: F) -> R where
    F: FnOnce(&mut dyn DynamicComponentDefinition<Message = M>) -> R, 
[src]

Execute a function on the underlying component definition and return the result. The component definition will be accessed as a DynamicComponentDefinition trait object.

This method will attempt to lock the mutex, and then apply f to the component definition inside the guard.

This method wraps the mutex guard in an additional allocation. Prefer Component::on_definition where possible.

Implementors

impl<C> AbstractComponent for Component<C> where
    C: ComponentTraits + ComponentLifecycle
[src]

Loading content...