Trait tide_disco::method::WriteState

source ·
pub trait WriteState: ReadState {
    // Required method
    fn write<'life0, 'async_trait, T>(
        &'life0 self,
        op: impl 'async_trait + Send + for<'a> FnOnce(&'a mut Self::State) -> BoxFuture<'a, T>,
    ) -> Pin<Box<dyn Future<Output = T> + Send + 'async_trait>>
       where T: 'async_trait,
             Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

A state which allows exclusive, write access.

Required Methods§

source

fn write<'life0, 'async_trait, T>( &'life0 self, op: impl 'async_trait + Send + for<'a> FnOnce(&'a mut Self::State) -> BoxFuture<'a, T>, ) -> Pin<Box<dyn Future<Output = T> + Send + 'async_trait>>
where T: 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Do an operation with mutable access to the state.

§Limitations

The reason this function takes a visitor function to apply to the state, rather than just returning a mutable reference to the state, is to allow implementations that cannot provide a plain mutable reference directly. For example, [RwLock] can produce a smart reference, a RwLockWriteGuard, but not a plain mutable reference.

Note that GATs may allow us to make this interface more ergonomic in the future. With stable GATs, this trait could be written like

trait WriteState {
    type State: 'static;
    type MutReference<'a>: 'a + DerefMut<Target = Self::State>;
    fn write(&self) -> Self::MutReference<'_>;
}

Like many function parameters in tide_disco, the function to apply to the state is also required to return a boxed future.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl WriteState for ()

This allows you to do api.post(...) in a simple API where the state is ().

source§

fn write<'life0, 'async_trait, T>( &'life0 self, op: impl 'async_trait + Send + for<'a> FnOnce(&'a mut Self::State) -> BoxFuture<'a, T>, ) -> Pin<Box<dyn Future<Output = T> + Send + 'async_trait>>
where T: 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

source§

impl<State: 'static + Send + Sync> WriteState for Mutex<State>

source§

fn write<'life0, 'async_trait, T>( &'life0 self, op: impl 'async_trait + Send + for<'a> FnOnce(&'a mut Self::State) -> BoxFuture<'a, T>, ) -> Pin<Box<dyn Future<Output = T> + Send + 'async_trait>>
where T: 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

source§

impl<State: 'static + Send + Sync> WriteState for RwLock<State>

source§

fn write<'life0, 'async_trait, T>( &'life0 self, op: impl 'async_trait + Send + for<'a> FnOnce(&'a mut Self::State) -> BoxFuture<'a, T>, ) -> Pin<Box<dyn Future<Output = T> + Send + 'async_trait>>
where T: 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

source§

impl<W: Send + Sync + WriteState> WriteState for Arc<W>

source§

fn write<'life0, 'async_trait, T>( &'life0 self, op: impl 'async_trait + Send + for<'a> FnOnce(&'a mut Self::State) -> BoxFuture<'a, T>, ) -> Pin<Box<dyn Future<Output = T> + Send + 'async_trait>>
where T: 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Implementors§