Trait PatchHugrMut

Source
pub trait PatchHugrMut: PatchVerification {
    type Outcome;

    const UNCHANGED_ON_FAILURE: bool;

    // Required method
    fn apply_hugr_mut(
        self,
        h: &mut impl HugrMut<Node = Self::Node>,
    ) -> Result<Self::Outcome, Self::Error>;
}
Expand description

A patch that can be applied to any HugrMut.

This trait is a generalisation of Patch in that it guarantees that the patch can be applied to any type implementing HugrMut.

§When to use

Prefer using the more general Patch trait in bounds where the type H is known. Resort to this trait if patches must be applicable to any HugrMut instance.

§When to implement

Always implement this trait when possible, to define how a patch is applied to any type implementing HugrMut. A blanket implementation ensures that any type implementing this trait also implements Patch.

Required Associated Constants§

Source

const UNCHANGED_ON_FAILURE: bool

If true, [self.apply]’s of this rewrite guarantee that they do not mutate the Hugr when they return an Err. If false, there is no guarantee; the Hugr should be assumed invalid when Err is returned.

Required Associated Types§

Source

type Outcome

The type returned on successful application of the rewrite.

Required Methods§

Source

fn apply_hugr_mut( self, h: &mut impl HugrMut<Node = Self::Node>, ) -> Result<Self::Outcome, Self::Error>

Mutate the specified Hugr, or fail with an error.

Returns Self::Outcome if successful. If [self.unchanged_on_failure] is true, then h must be unchanged if Err is returned. See also [self.verify]

§Panics

May panic if-and-only-if h would have failed Hugr::validate; that is, implementations may begin with assert!(h.validate()), with debug_assert!(h.validate()) being preferred.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§