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/// This is used by the [`Bridge`](crate::bridge::Bridge) to serialize effects going across the
16/// FFI boundary. If you don't need serialization and FFI, use [`Effect`].
17///
18/// You should annotate your type with `#[effect(typegen)]` to implement this trait.
19// used in docs/internals/bridge.md
20// ANCHOR: effect_typegen
21pub trait EffectFFI: Effect {
22 /// Ffi is an enum with variants corresponding to the Effect variants
23 /// but instead of carrying a `Request<Op>` they carry the `Op` directly
24 type Ffi: Serialize;
25
26 /// Converts the `Effect` into its FFI counterpart and returns it alongside
27 /// a deserializing version of the resolve callback for the request that the
28 /// original `Effect` was carrying.
29 ///
30 /// You should not need to call this method directly. It is called by
31 /// the [`Bridge`](crate::bridge::Bridge)
32 fn serialize<T: FfiFormat>(self) -> (Self::Ffi, ResolveSerialized<T>);
33}
34// ANCHOR_END: effect_typegen