hugr_core::hugr::rewrite

Trait Rewrite

source
pub trait Rewrite {
    type Error: Error;
    type ApplyResult;

    const UNCHANGED_ON_FAILURE: bool;

    // Required methods
    fn verify(&self, h: &impl HugrView) -> Result<(), Self::Error>;
    fn apply(
        self,
        h: &mut impl HugrMut,
    ) -> Result<Self::ApplyResult, Self::Error>;
    fn invalidation_set(&self) -> impl Iterator<Item = Node>;
}
Expand description

An operation that can be applied to mutate a Hugr

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 Error: Error

The type of Error with which this Rewrite may fail

source

type ApplyResult

The type returned on successful application of the rewrite.

Required Methods§

source

fn verify(&self, h: &impl HugrView) -> Result<(), Self::Error>

Checks whether the rewrite would succeed on the specified Hugr. If this call succeeds, [self.apply] should also succeed on the same h If this calls fails, [self.apply] would fail with the same error.

source

fn apply(self, h: &mut impl HugrMut) -> Result<Self::ApplyResult, Self::Error>

Mutate the specified Hugr, or fail with an error. Returns Self::ApplyResult 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.

source

fn invalidation_set(&self) -> impl Iterator<Item = Node>

Returns a set of nodes referenced by the rewrite. Modifying any of these nodes will invalidate it.

Two impl Rewrites can be composed if their invalidation sets are disjoint.

Object Safety§

This trait is not object safe.

Implementors§