pub struct StructuralMutatorView<'a, D, Base = StructuralMutatorObj> { /* private fields */ }Expand description
The running structural mutation, passed to each handler.
A handler that matches a node decides how its children are rewritten: call
default_mutate to rewrite every child through the
dispatcher, mutate to rewrite one value, or neither to
leave the children as they are. Pass the handler’s own self as dispatch
to every method.
See also structural_mutate.
Implementations§
Source§impl<D, Base: StructuralMutatorBase> StructuralMutatorView<'_, D, Base>
impl<D, Base: StructuralMutatorBase> StructuralMutatorView<'_, D, Base>
Sourcepub fn base(&self) -> &Base
pub fn base(&self) -> &Base
Inspect the base state without retaining the scoped mutator runtime.
§Returns
The base state, borrowed for the lifetime of this view.
Sourcepub fn def_region_kind(&self) -> DefRegionKind
pub fn def_region_kind(&self) -> DefRegionKind
Return the definition region the current value is in.
Reflected fields marked as definitions set it while their values are
mutated; it is DefRegionKind::None elsewhere.
§Returns
The current definition region.
Sourcepub fn with_def_region_kind<R>(
&mut self,
kind: DefRegionKind,
callback: impl FnOnce(&mut StructuralMutatorView<'_, D, Base>) -> R,
) -> R
pub fn with_def_region_kind<R>( &mut self, kind: DefRegionKind, callback: impl FnOnce(&mut StructuralMutatorView<'_, D, Base>) -> R, ) -> R
Run callback under a scoped definition region.
An enclosing DefRegionKind::Pattern region keeps precedence, since a
pattern applies to everything inside it. The previous region is restored
afterwards.
§Arguments
kind- The definition region to enter.callback- Runs inside the region, with this view.
§Returns
The result of callback.
Sourcepub fn mutate<'input, T>(
&mut self,
dispatch: &mut D,
value: impl Into<MutationView<'input, T>>,
) -> Result<UnchangedOr<Any>>
pub fn mutate<'input, T>( &mut self, dispatch: &mut D, value: impl Into<MutationView<'input, T>>, ) -> Result<UnchangedOr<Any>>
Mutate value through the dispatcher, as if the traversal had reached it.
value keeps the mode it carries. Use it to rewrite a value other
than the current node, such as a field selected with
MutationView::field.
§Arguments
dispatch- The handler’s ownself.value- The value to mutate.
§Returns
The replacement, or Unchanged.
§Errors
Returns the error of the handler that value reaches.
Sourcepub fn default_mutate<'input, T>(
&mut self,
dispatch: &mut D,
value: impl Into<MutationView<'input, T>>,
) -> Result<UnchangedOr<Any>>
pub fn default_mutate<'input, T>( &mut self, dispatch: &mut D, value: impl Into<MutationView<'input, T>>, ) -> Result<UnchangedOr<Any>>
Rewrite the children of value through the dispatcher, without dispatching
value itself again.
Children are found by the type’s registered mutation hook or its reflected
fields. A hook uses the mutator only through its arguments, during the
call, and must not keep it or call it outside them. The result is
unchanged when no child changed; otherwise it is a node with the new
children, made in place when value allows it and is uniquely owned.
§Arguments
dispatch- The handler’s ownself.value- The value whose children to mutate, usually the view the handler received.
§Returns
The rewritten node, or Unchanged.
§Errors
Returns the first error of a child’s handler.
Sourcepub fn var_remap_get(
&mut self,
dispatch: &mut D,
var: AnyView<'_>,
) -> Result<Option<Any>>
pub fn var_remap_get( &mut self, dispatch: &mut D, var: AnyView<'_>, ) -> Result<Option<Any>>
Look up the replacement recorded for a variable in this mutation.
Default mutation records the result of every free variable and DAG node it rewrites, and replaces each later occurrence with it.
§Arguments
dispatch- The handler’s ownself.var- The variable, an object.
§Returns
The recorded replacement, or None.
§Errors
Returns a TypeError if var is not an object.
Sourcepub fn var_remap_set(
&mut self,
dispatch: &mut D,
var: AnyView<'_>,
value: &Any,
) -> Result<()>
pub fn var_remap_set( &mut self, dispatch: &mut D, var: AnyView<'_>, value: &Any, ) -> Result<()>
Record a replacement for a variable for the rest of this mutation.
Default mutation then replaces each later occurrence of var, a free
variable or DAG node, with value.
§Arguments
dispatch- The handler’s ownself.var- The variable, an object.value- The replacement.
§Returns
Ok(()) once the replacement is recorded.
§Errors
Returns a TypeError if var is not an object.