Skip to main content

Module client

Module client 

Source
Expand description

Runtime-scoped client capabilities.

A Scope can only be issued by the runtime from the exact selected provider. Providers turn that zero-sized capability into their public client handle without retaining the transient selector borrow.

The application lifetime cannot escape crate::executor::session::Session::with_app:

ⓘ
use dope_runtime::{
    client::Provider,
    executor::{self, Application},
};

fn escape<'scope, 'd, D>(
    session: &mut executor::session::Session<'scope, 'd>,
    dispatcher: D,
) -> D::Client<'d>
where
    'd: 'scope,
    D: Application<'d> + Provider<'d>,
{
    session.with_app(dispatcher, |mut app| app.client(|dispatcher| dispatcher))
}

A scope cannot be constructed outside the runtime:

ⓘ
use dope_runtime::client::Scope;

let _ = Scope::<'static, 'static, ()>::new();

The provider-erased application lease is equally unforgeable:

ⓘ
use dope_runtime::client::Lease;

let _ = Lease::<'static, 'static>::new();

A provider cannot turn the selector’s transient borrow into an application-scoped reference:

ⓘ
use std::pin::Pin;
use dope_runtime::client::{Provider, Scope};

struct Borrowing;

impl<'d> Provider<'d> for Borrowing {
    type Client<'app> = &'app Borrowing where 'd: 'app;

    fn provide<'app>(
        self: Pin<&Self>,
        _scope: Scope<'app, 'd, Self>,
    ) -> Self::Client<'app>
    where
        'd: 'app,
    {
        self.get_ref()
    }
}

The higher-ranked selector likewise cannot save its dispatcher borrow:

ⓘ
use std::pin::Pin;
use dope_runtime::{
    client::Provider,
    executor::{self, Application},
};

fn transient<'app, 'd, D>(
    app: &mut executor::session::Application<'app, 'd, D>,
) -> Pin<&'app D>
where
    'd: 'app,
    D: Application<'d> + Provider<'d>,
{
    let mut leaked = None;
    let _ = app.client(|dispatcher| {
        leaked = Some(dispatcher);
        dispatcher
    });
    leaked.unwrap()
}

Structs§

Anchor
Address-stable provider root borrowed for one scoped composition. Its private constructor pairs the client scope with this exact root.
Lease
Provider-erased, zero-sized runtime scope proof. It does not claim which provider issued it or remains installed.
Scope
An unforgeable, zero-sized proof that exact provider type P issued a client in runtime scope 'app and driver scope 'd.

Traits§

Composition
Runs one application composition around an address-stable provider root. Neither scoped input can appear in Self::Output.
Provider
Produces a client from the exact selected provider. The result may retain only runtime scope, not the selector borrow.