pub struct Selector {
pub operation: Operation,
pub anchor: String,
pub end: Option<String>,
}Fields§
§operation: OperationThe type of edit operation to perform.
Insert Operations
insert_before- Insert content immediately before the anchor textinsert_after- Insert content immediately after the anchor textinsert_after_node- Insert content after the complete AST node containing the anchor
Replace Operations
replace_exact- Replace only the exact anchor textreplace_node- Replace the entire AST node containing the anchorreplace_range- Replace everything from anchor to end (requiresendfield)
§Choosing the Right Operation
For adding new code:
- Use
insert_beforeorinsert_afterfor precise placement - Use
insert_after_nodewhen you want to add after a complete statement/declaration
For changing existing code:
- Use
replace_exactfor small, precise text changes - Use
replace_nodefor changing entire functions, classes, blocks, or statements - Use
replace_rangefor changing multi-line sections with clear start/end boundaries
anchor: StringText to locate in the source code as the target for the operation.
Should be a short, distinctive piece of text that uniquely identifies the location. For range operations, this marks the start of the range. For node operations, this should cover the start of the ast node.
Tips for Good Anchors
- Keep anchors short but unique - “fn main” instead of the entire function signature
- Use distinctive text - function names, keywords, or unique comments work well
- Avoid whitespace-only anchors - they’re often not unique enough
- Test your anchor - if it appears multiple times, the tool will find the best placement
§Examples
"fn main() {"- Targets a function definition"struct User {"- Targets a struct definition"// TODO: implement"- Targets a specific comment"import React"- Targets an import statement
end: Option<String>End boundary for replace range operations only.
When specified, defines the end of the text range to be replaced. Use this to avoid repeating long blocks of content just to replace them.
§Example
{
"operation": "replace_range",
"anchor": "// Start replacing here",
"end": "// Stop replacing here"
}Implementations§
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Selector
impl<'de> Deserialize<'de> for Selector
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl JsonSchema for Selector
impl JsonSchema for Selector
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Returns a string that uniquely identifies the schema produced by this type. Read more
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
Whether JSON Schemas generated for this type should be included directly in parent schemas,
rather than being re-used where possible using the
$ref keyword. Read moreAuto Trait Implementations§
impl Freeze for Selector
impl RefUnwindSafe for Selector
impl Send for Selector
impl Sync for Selector
impl Unpin for Selector
impl UnsafeUnpin for Selector
impl UnwindSafe for Selector
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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> ⓘ
Converts
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> ⓘ
Converts
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