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§
Sourcefn 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,
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.
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 WriteState for ()
This allows you to do api.post(...)
in a simple API where the state is ()
.
impl WriteState for ()
This allows you to do api.post(...)
in a simple API where the state is ()
.