Derive Macro depends::derives::Operation

source ·
#[derive(Operation)]
Expand description

Mark this type as a an Operation. This implements Named for debugging, which is a requirement to implement UpdateDerived.

Usage

#[derive(Operation)]
struct Square;

// Note [TwoNumbersRef] is generated by the [Dependencies] macro, and
// represents read-references to all of its fields.
impl UpdateDerived for Square {
    // [SingleRef] is used for a single dependency.
    // If you have more than one, you must use a struct which derives
    // [Dependencies].
    type Input<'a> = SingleRef<'a> where Self: 'a;
    // [TargetMut] is short-hand for a mutable reference to the target.
    // For this [Operation], the target is a [NumberValue].
    type Target<'a> = TargetMut<'a, NumberValue> where Self: 'a;

    fn update_derived(
        value: SingleRef<'_>,
        mut target: TargetMut<'_, NumberValue>,
    ) -> Result<(), EarlyExit> {
        target.value = input.value.pow(2);
        // Returning [EarlyExit] will cause the graph to stop resolving.
        Ok(())
    }
}