crux_core/core/effect.rs
1use serde::Serialize;
2
3use crate::bridge::{FfiFormat, ResolveSerialized};
4
5/// Implemented automatically with the effect macro from `crux_macros`.
6/// This is a marker trait to ensure the macro generated traits are present on the effect type.
7///
8/// You should annotate your type with `#[effect]` to implement this trait.
9// used in docs/internals/bridge.md
10// ANCHOR: effect
11pub trait Effect: Send + 'static {}
12// ANCHOR_END: effect
13
14/// Implemented automatically with the effect macro from `crux_macros`.
15///
16/// This is used by the [`Bridge`](crate::bridge::Bridge) to serialize effects going across the
17/// FFI boundary. If you don't need serialization and FFI, use [`Effect`].
18///
19/// You should annotate your type with `#[effect(typegen)]` to implement this trait.
20// used in docs/internals/bridge.md
21// ANCHOR: effect_typegen
22pub trait EffectFFI: Effect {
23 /// Ffi is an enum with variants corresponding to the Effect variants
24 /// but instead of carrying a `Request<Op>` they carry the `Op` directly
25 type Ffi: Serialize;
26
27 /// Converts the `Effect` into its FFI counterpart and returns it alongside
28 /// a deserializing version of the resolve callback for the request that the
29 /// original `Effect` was carrying.
30 ///
31 /// You should not need to call this method directly. It is called by
32 /// the [`Bridge`](crate::bridge::Bridge)
33 fn serialize<T: FfiFormat>(self) -> (Self::Ffi, ResolveSerialized<T>);
34}
35// ANCHOR_END: effect_typegen