pub trait FormatHolder {
// Required methods
fn visit<'a>(
&'a self,
f: &mut dyn FnMut(&'a Format) -> Result<()>,
) -> Result<()>;
fn visit_mut(
&mut self,
f: &mut dyn FnMut(&mut Format) -> Result<()>,
) -> Result<()>;
fn unify(&mut self, other: Self) -> Result<()>;
fn is_unknown(&self) -> bool;
// Provided methods
fn normalize(&mut self) -> Result<()> { ... }
fn reduce(&mut self) { ... }
}Expand description
Common methods for nodes in the AST of formats.
Required Methods§
Sourcefn visit<'a>(
&'a self,
f: &mut dyn FnMut(&'a Format) -> Result<()>,
) -> Result<()>
fn visit<'a>( &'a self, f: &mut dyn FnMut(&'a Format) -> Result<()>, ) -> Result<()>
Visit all the formats in self in a depth-first way.
Variables are not supported and will cause an error.
Sourcefn visit_mut(
&mut self,
f: &mut dyn FnMut(&mut Format) -> Result<()>,
) -> Result<()>
fn visit_mut( &mut self, f: &mut dyn FnMut(&mut Format) -> Result<()>, ) -> Result<()>
Mutably visit all the formats in self in a depth-first way.
- Replace variables (if any) with their known values then apply the
visiting function
f. - Return an error if any variable has still an unknown value (thus cannot be removed).
Sourcefn unify(&mut self, other: Self) -> Result<()>
fn unify(&mut self, other: Self) -> Result<()>
Update variables and add missing enum variants so that the terms match. This is a special case of term unification:
- Variables occurring in
othermust be “fresh” and distinct from each other. By “fresh”, we mean that they do not occur inselfand have no known value yet. - If needed, enums in
selfwill be extended with new variants taken fromother. - Although the parameter
otheris consumed (i.e. taken by value), all variables occurring either inselforotherare correctly updated.
Sourcefn is_unknown(&self) -> bool
fn is_unknown(&self) -> bool
Whether this format is a variable with no known value yet.
Provided Methods§
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.