pub struct FileChange {
pub path: String,
pub kind: ChangeKind,
pub added: usize,
pub removed: usize,
pub hunks: Vec<Hunk>,
pub before_text: Option<String>,
pub before: Option<FileState>,
pub after: Option<FileState>,
}Expand description
One file a tool call changed.
Fields§
§path: StringThe file: an absolute path when the tool knows the directory it ran in, as rig-tools’ file tools do, else as the call named it.
kind: ChangeKindWhat happened to it.
added: usizeLines added.
removed: usizeLines removed.
hunks: Vec<Hunk>The change as hunks, each line with its ending, with three lines of
context; none when the tool did not diff the file (such as one too
large to read). unified renders them as a diff.
before_text: Option<String>The file’s text before the change, when the tool read it whole as
UTF-8 within its read limit; None for a created file.
after_text is it with the hunks applied.
before: Option<FileState>The file before the change, when the tool or a checkpoint around it
knows it; None for a created file.
after: Option<FileState>The file the change left, when the tool knows it; None for a
deleted file.
Implementations§
Source§impl FileChange
impl FileChange
Sourcepub fn created(path: impl Into<String>, lines: usize) -> Self
pub fn created(path: impl Into<String>, lines: usize) -> Self
path was created with lines lines.
Sourcepub fn modified(path: impl Into<String>, added: usize, removed: usize) -> Self
pub fn modified(path: impl Into<String>, added: usize, removed: usize) -> Self
path was changed: added lines added and removed removed.
Sourcepub fn deleted(path: impl Into<String>, lines: usize) -> Self
pub fn deleted(path: impl Into<String>, lines: usize) -> Self
path, which had lines lines, was deleted.
Sourcepub fn with_hunks(self, hunks: Vec<Hunk>) -> Self
pub fn with_hunks(self, hunks: Vec<Hunk>) -> Self
This change, made by hunks.
Sourcepub fn with_before_text(self, text: impl Into<String>) -> Self
pub fn with_before_text(self, text: impl Into<String>) -> Self
This change, made to a file that held text.
Sourcepub fn unified(&self) -> String
pub fn unified(&self) -> String
The change as a unified diff, its hunks under a ---/+++ header
naming the path (/dev/null on the side with no file); empty when
it has no hunks.
use rig_core::tool::{FileChange, Hunk, HunkLine, Lines};
let change = FileChange::modified("a.rs", 1, 1).with_hunks(vec![Hunk {
old: Lines { start: 1, count: 2 },
new: Lines { start: 1, count: 2 },
lines: vec![
HunkLine::Same("one\n".into()),
HunkLine::Removed("two\n".into()),
HunkLine::Added("2".into()),
],
}]);
assert_eq!(
change.unified(),
"--- a.rs\n+++ a.rs\n@@ -1,2 +1,2 @@\n one\n-two\n+2\n\\ No newline at end of file\n"
);Sourcepub fn after_text(&self) -> Option<String>
pub fn after_text(&self) -> Option<String>
The file’s text after the change: before_text
(empty for a created file) with the hunks applied. None for a
deleted file, when the text before is not known, or when the hunks
do not make the whole change (they do not count the lines
added and removed, or do not fit
the text before).
use rig_core::tool::{FileChange, Hunk, HunkLine, Lines};
let change = FileChange::modified("a.rs", 1, 1)
.with_before_text("one\ntwo\n")
.with_hunks(vec![Hunk {
old: Lines { start: 2, count: 1 },
new: Lines { start: 2, count: 1 },
lines: vec![HunkLine::Removed("two\n".into()), HunkLine::Added("2\n".into())],
}]);
assert_eq!(change.after_text().as_deref(), Some("one\n2\n"));
assert_eq!(change.changed_lines().collect::<Vec<_>>(), [2]);Sourcepub fn changed_lines(&self) -> impl Iterator<Item = usize> + '_
pub fn changed_lines(&self) -> impl Iterator<Item = usize> + '_
The lines the change added or rewrote, counted from 1 in the file after it.
Sourcepub fn with_before(self, before: FileState) -> Self
pub fn with_before(self, before: FileState) -> Self
This change, made to the file before.
Sourcepub fn with_after(self, after: FileState) -> Self
pub fn with_after(self, after: FileState) -> Self
This change, leaving the file after.
Trait Implementations§
Source§impl Clone for FileChange
impl Clone for FileChange
Source§impl Debug for FileChange
impl Debug for FileChange
Source§impl<'de> Deserialize<'de> for FileChange
impl<'de> Deserialize<'de> for FileChange
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>,
impl Eq for FileChange
Source§impl PartialEq for FileChange
impl PartialEq for FileChange
Source§impl Serialize for FileChange
impl Serialize for FileChange
impl StructuralPartialEq for FileChange
Auto Trait Implementations§
impl Freeze for FileChange
impl RefUnwindSafe for FileChange
impl Send for FileChange
impl Sync for FileChange
impl Unpin for FileChange
impl UnsafeUnpin for FileChange
impl UnwindSafe for FileChange
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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<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.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