pub struct MutationRegistry { /* private fields */ }Expand description
Central registry for MutationSpec → Mutation conversion
Routes each MutationSpec to its appropriate Converter based on kind_name().
Implementations§
Source§impl MutationRegistry
impl MutationRegistry
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new registry with all built-in converters registered
Uses register_all() for converters that handle multiple spec kinds,
which automatically registers all kinds from spec_kinds().
This prevents the “forgot to register” bug.
Sourcepub fn register(
&mut self,
kind: &'static str,
converter: Box<dyn MutationConverter>,
)
pub fn register( &mut self, kind: &'static str, converter: Box<dyn MutationConverter>, )
Register a converter for a single spec kind
Note: Each spec kind can only have one converter.
For converters handling multiple spec kinds, use register_all().
Sourcepub fn register_all<C: MutationConverter + Default + 'static>(&mut self)
pub fn register_all<C: MutationConverter + Default + 'static>(&mut self)
Register a converter for all its spec_kinds() automatically.
This method creates a new instance of the converter for each spec kind
it handles. Requires the converter to implement Default.
§Example
// Instead of:
registry.register("FilterNext", Box::new(IdiomConverter::new()));
registry.register("MapUnwrapOr", Box::new(IdiomConverter::new()));
// ... 15 more lines
// Use:
registry.register_all::<IdiomConverter>();Sourcepub fn can_handle(&self, spec: &MutationSpec) -> bool
pub fn can_handle(&self, spec: &MutationSpec) -> bool
Check if this registry can handle the given spec
Sourcepub fn get(&self, spec: &MutationSpec) -> Option<&dyn MutationConverter>
pub fn get(&self, spec: &MutationSpec) -> Option<&dyn MutationConverter>
Get the converter for a spec, if registered
Sourcepub fn convert(
&self,
spec: &MutationSpec,
) -> Result<Box<dyn Mutation>, ConvertError>
👎Deprecated since 0.1.0: Returns Box<dyn Mutation> for legacy apply(&mut PureFile). Use convert_v2() for ASTRegApply.
pub fn convert( &self, spec: &MutationSpec, ) -> Result<Box<dyn Mutation>, ConvertError>
Returns Box<dyn Mutation> for legacy apply(&mut PureFile). Use convert_v2() for ASTRegApply.
Convert a MutationSpec to a Mutation (DEPRECATED)
Sourcepub fn convert_v2(
&self,
spec: &MutationSpec,
ctx: &AnalysisContext,
) -> Result<Vec<Box<dyn ASTRegApply>>, ConvertError>
pub fn convert_v2( &self, spec: &MutationSpec, ctx: &AnalysisContext, ) -> Result<Vec<Box<dyn ASTRegApply>>, ConvertError>
Convert a MutationSpec to execution units (V2 API)
Returns a vector of ASTRegApply mutations that implement the spec. One spec may expand to multiple execution units.
§Returns
Ok(mutations)- Vector of mutations to executeErr(V2NotSupported)- Converter doesn’t implement convert_v2 yetErr(UnknownSpec)- No converter registered for this spec kind
Sourcepub fn pre_check(
&self,
spec: &MutationSpec,
ctx: &AnalysisContext,
) -> Result<(), ConvertError>
pub fn pre_check( &self, spec: &MutationSpec, ctx: &AnalysisContext, ) -> Result<(), ConvertError>
Pre-check a MutationSpec before applying.
Uses GraphChecker to validate that targets exist before mutation.
This catches errors early (e.g., field not found, type not found)
without running cargo check.
§Checks performed
| Spec Kind | Check |
|---|---|
| Rename | Target symbol exists |
| AddField/RemoveField | Struct exists |
| AddDerive/RemoveDerive | Target type exists |
| AddVariant/RemoveVariant | Enum exists |
| AddMethod/RemoveMethod | Target type exists |
| ChangeVisibility | Target exists |
Sourcepub fn registered_kinds(&self) -> Vec<&'static str>
pub fn registered_kinds(&self) -> Vec<&'static str>
Get all registered spec kinds
Trait Implementations§
Source§impl Debug for MutationRegistry
impl Debug for MutationRegistry
Auto Trait Implementations§
impl Freeze for MutationRegistry
impl !RefUnwindSafe for MutationRegistry
impl Send for MutationRegistry
impl Sync for MutationRegistry
impl Unpin for MutationRegistry
impl UnsafeUnpin for MutationRegistry
impl !UnwindSafe for MutationRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more