pub struct Component {
pub name: String,
pub attrs: HashMap<String, String>,
pub open_start: usize,
pub open_end: usize,
pub close_start: usize,
pub close_end: usize,
}Expand description
A parsed component in a document.
Components are bounded regions marked by <!-- agent:name -->...<!-- /agent:name -->.
Opening tags may contain inline attributes: <!-- agent:name key=value -->.
Fields§
§name: String§attrs: HashMap<String, String>Inline attributes parsed from the opening tag (e.g., patch=append).
open_start: usizeByte offset of < in opening marker.
open_end: usizeByte offset past > in opening marker (includes trailing newline if present).
close_start: usizeByte offset of < in closing marker.
close_end: usizeByte offset past > in closing marker (includes trailing newline if present).
Implementations§
Source§impl Component
impl Component
Sourcepub fn content<'a>(&self, doc: &'a str) -> &'a str
pub fn content<'a>(&self, doc: &'a str) -> &'a str
Extract the content between the opening and closing markers.
Sourcepub fn patch_mode(&self) -> Option<&str>
pub fn patch_mode(&self) -> Option<&str>
Get the patch mode from inline attributes.
Checks patch= first, falls back to mode= for backward compatibility.
Sourcepub fn replace_content(&self, doc: &str, new_content: &str) -> String
pub fn replace_content(&self, doc: &str, new_content: &str) -> String
Replace the content between markers, returning the new document. The markers themselves are preserved.
Sourcepub fn append_with_caret(
&self,
doc: &str,
content: &str,
caret_offset: Option<usize>,
) -> String
pub fn append_with_caret( &self, doc: &str, content: &str, caret_offset: Option<usize>, ) -> String
Append content into this component, inserting before the caret position if the caret is inside the component. Falls back to normal append if the caret is outside the component.
caret_offset: byte offset of the caret in the document. Pass None for
normal append behavior.
Sourcepub fn append_with_boundary(
&self,
doc: &str,
content: &str,
boundary_id: &str,
) -> String
pub fn append_with_boundary( &self, doc: &str, content: &str, boundary_id: &str, ) -> String
Append content into this component at the boundary marker position.
Finds <!-- agent:boundary:ID --> inside the component. If found,
inserts content at the line start of the boundary marker (replacing
the marker). Falls back to normal append if the boundary is not found.
Trait Implementations§
impl Eq for Component
impl StructuralPartialEq for Component
Auto Trait Implementations§
impl Freeze for Component
impl RefUnwindSafe for Component
impl Send for Component
impl Sync for Component
impl Unpin for Component
impl UnsafeUnpin for Component
impl UnwindSafe for Component
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.