Trait Patch

Source
pub trait Patch<H: HugrView>: PatchVerification<Node = H::Node> {
    type Outcome;

    const UNCHANGED_ON_FAILURE: bool;

    // Required method
    fn apply(self, h: &mut H) -> Result<Self::Outcome, Self::Error>;
}
Expand description

A patch that can be applied to a mutable Hugr of type H.

§When to use

Use this trait whenever possible in bounds for the most generality. Note that this will require specifying which type H the patch applies to.

§When to implement

For patches that work on any H: HugrMut, prefer implementing PatchHugrMut instead. This will automatically implement this trait.

Required Associated Constants§

Source

const UNCHANGED_ON_FAILURE: bool

If true, Patch::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(self, h: &mut H) -> Result<Self::Outcome, Self::Error>

Mutate the specified Hugr, or fail with an error.

Returns Self::Outcome if successful. If Patch::UNCHANGED_ON_FAILURE is true, then h must be unchanged if Err is returned. See also PatchVerification::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§