#[derive(Recall)]
{
// Attributes available to this derive:
#[recallable]
}
Expand description
Derive macro that generates the Recall trait implementation.
For plain fields, recall assigns the memento value directly. For fields annotated
with #[recallable], it recursively calls recall on the nested value.
Fields marked #[recallable(skip)] are left untouched.
For #[recallable] fields, replace/merge behavior comes from the field type’s own
Recall implementation.
Lifetime parameters are supported only when the generated memento can stay owned:
non-skipped fields may not borrow one of the struct’s lifetimes. Skipped borrowed
fields and lifetime-only markers such as PhantomData<&'a T> are allowed.
This example requires the serde feature.
use recallable::{Recall, Recallable};
#[derive(Clone, Debug, serde::Serialize, Recallable, Recall)]
struct State {
score: i32,
#[recallable(skip)]
cached_label: String,
}
let mut state = State { score: 0, cached_label: "stale".into() };
let memento: <State as Recallable>::Memento =
serde_json::from_str(r#"{"score":42}"#).unwrap();
state.recall(memento);
assert_eq!(state.score, 42);
assert_eq!(state.cached_label, "stale"); // skip preserves the valueDerive macro that generates the Recall trait implementation.
The generated recall method:
- assigns fields directly by default,
- recursively calls
recallon fields marked with#[recallable], - respects
#[recallable(skip)]by omitting those fields from recalling.
For #[recallable] fields, replace/merge behavior comes from the field type’s own
Recall implementation.