Skip to main content

dope_runtime/client/
context.rs

1use std::pin;
2
3use crate::client::Bound;
4
5/// The exact selected provider and its application lifetime, issued together.
6///
7/// The short provider borrow cannot escape into a client. Private construction
8/// prevents rebuilding this capability with a different provider.
9pub struct Context<'borrow, 'app: 'borrow, 'd: 'app, P: ?Sized> {
10    provider: pin::Pin<&'borrow P>,
11    bound: Bound<'app, 'd, P>,
12}
13
14impl<'borrow, 'app: 'borrow, 'd: 'app, P: ?Sized> Context<'borrow, 'app, 'd, P> {
15    pub(crate) const fn new(provider: pin::Pin<&'borrow P>) -> Self {
16        Self {
17            provider,
18            bound: Bound::new(),
19        }
20    }
21
22    pub fn into_parts(self) -> (pin::Pin<&'borrow P>, Bound<'app, 'd, P>) {
23        (self.provider, self.bound)
24    }
25}
26
27const _: () = {
28    assert!(std::mem::size_of::<Context<'_, '_, '_, ()>>() == std::mem::size_of::<&()>());
29    assert!(!std::mem::needs_drop::<Context<'_, '_, '_, ()>>());
30};