crux_core/core/
effect.rs

1use serde::Serialize;
2
3use crate::bridge::ResolveSerialized;
4
5/// Implemented automatically with the Effect macro from `crux_macros`.
6/// This is used by the [`Bridge`](crate::bridge::Bridge) to serialize effects going across the
7/// FFI boundary.
8// used in docs/internals/bridge.md
9// ANCHOR: effect
10pub trait Effect: Send + 'static {
11    /// Ffi is an enum with variants corresponding to the Effect variants
12    /// but instead of carrying a `Request<Op>` they carry the `Op` directly
13    type Ffi: Serialize;
14
15    /// Converts the `Effect` into its FFI counterpart and returns it alongside
16    /// a deserializing version of the resolve callback for the request that the
17    /// original `Effect` was carrying.
18    ///
19    /// You should not need to call this method directly. It is called by
20    /// the [`Bridge`](crate::bridge::Bridge)
21    fn serialize(self) -> (Self::Ffi, ResolveSerialized);
22}
23// ANCHOR_END: effect