Skip to main content

StructuralMutatorView

Struct StructuralMutatorView 

Source
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>

Source

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.

Source

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.

Source

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.

Source

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 own self.
  • value - The value to mutate.
§Returns

The replacement, or Unchanged.

§Errors

Returns the error of the handler that value reaches.

Source

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 own self.
  • 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.

Source

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 own self.
  • var - The variable, an object.
§Returns

The recorded replacement, or None.

§Errors

Returns a TypeError if var is not an object.

Source

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 own self.
  • 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.

Auto Trait Implementations§

§

impl<'a, D, Base = StructuralMutatorObj> !RefUnwindSafe for StructuralMutatorView<'a, D, Base>

§

impl<'a, D, Base = StructuralMutatorObj> !Send for StructuralMutatorView<'a, D, Base>

§

impl<'a, D, Base = StructuralMutatorObj> !Sync for StructuralMutatorView<'a, D, Base>

§

impl<'a, D, Base = StructuralMutatorObj> !UnwindSafe for StructuralMutatorView<'a, D, Base>

§

impl<'a, D, Base> Freeze for StructuralMutatorView<'a, D, Base>

§

impl<'a, D, Base> Unpin for StructuralMutatorView<'a, D, Base>

§

impl<'a, D, Base> UnsafeUnpin for StructuralMutatorView<'a, D, Base>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TypeSubsumes<T> for T
where T: ?Sized,