Trait WithContext

Source
pub trait WithContext<Ev, Ef> {
    // Required method
    fn new_with_context(context: ProtoContext<Ef, Ev>) -> Self;
}
Expand description

Allows Crux to construct app’s set of required capabilities, providing context they can then use to request effects and dispatch events.

new_with_context is called by Crux and should return an instance of the app’s Capabilities type with all capabilities constructed with context passed in. Use Context::specialize to create an appropriate context instance with the effect constructor which should wrap the requested operations.

Note that this implementation can be generated by the derive macro crux_core::macros::Effect.

impl crux_core::WithContext<Event, Effect> for Capabilities {
    fn new_with_context(
        context: crux_core::capability::ProtoContext<Effect, Event>,
    ) -> Capabilities {
        Capabilities {
            http: crux_http::Http::new(context.specialize(Effect::Http)),
            render: crux_core::render::Render::new(context.specialize(Effect::Render)),
        }
    }
}

Required Methods§

Source

fn new_with_context(context: ProtoContext<Ef, Ev>) -> Self

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.

Implementations on Foreign Types§

Source§

impl<Event, Effect> WithContext<Event, Effect> for ()

Source§

fn new_with_context(_context: ProtoContext<Effect, Event>) -> Self

Implementors§