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§
Sourceconst UNCHANGED_ON_FAILURE: bool
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§
Sourcetype ApplyResult
type ApplyResult
The type returned on successful application of the rewrite.
Required Methods§
Sourcefn verify(&self, h: &impl HugrView) -> Result<(), Self::Error>
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.
Sourcefn apply(self, h: &mut impl HugrMut) -> Result<Self::ApplyResult, Self::Error>
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.
Sourcefn invalidation_set(&self) -> impl Iterator<Item = Node>
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 Rewrite
s can be composed if their invalidation sets are
disjoint.
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.