Skip to main content

Service

Trait Service 

Source
pub trait Service: Clone + 'static {
    const NAME: &'static str;

    // Provided methods
    fn to_context(self) -> ServiceContext
       where Self: Sized { ... }
    fn layer(self) -> Layer<Self, Never, ()>
       where Self: Sized { ... }
    fn use_<A, E, R, F>(f: F) -> Effect<A, E, R>
       where Self: Sized,
             A: 'static,
             E: From<MissingService> + 'static,
             R: ServiceLookup<Self> + 'static,
             F: FnOnce(Self) -> Effect<A, E, R> + 'static { ... }
    fn use_sync<A, E, R, F>(f: F) -> Effect<A, E, R>
       where Self: Sized,
             A: 'static,
             E: From<MissingService> + 'static,
             R: ServiceLookup<Self> + 'static,
             F: FnOnce(Self) -> A + 'static { ... }
}
Expand description

Service marker implemented by #[derive(Service)].

A service type is both the key and the value stored in ServiceContext. This intentionally mirrors Effect v4’s Context.Service class style while staying Rust-native.

Required Associated Constants§

Source

const NAME: &'static str

Human-readable service name used in diagnostics.

Provided Methods§

Source

fn to_context(self) -> ServiceContext
where Self: Sized,

Wrap this service in a fresh ServiceContext.

Source

fn layer(self) -> Layer<Self, Never, ()>
where Self: Sized,

Build a layer that provides this concrete service value.

Source

fn use_<A, E, R, F>(f: F) -> Effect<A, E, R>
where Self: Sized, A: 'static, E: From<MissingService> + 'static, R: ServiceLookup<Self> + 'static, F: FnOnce(Self) -> Effect<A, E, R> + 'static,

Access this service and pass it to an effectful callback.

Source

fn use_sync<A, E, R, F>(f: F) -> Effect<A, E, R>
where Self: Sized, A: 'static, E: From<MissingService> + 'static, R: ServiceLookup<Self> + 'static, F: FnOnce(Self) -> A + 'static,

Access this service and pass it to a synchronous callback.

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.

Implementors§