pub struct Edit {
pub step: u32,
pub tool: String,
pub path: String,
pub lines_added: u64,
pub lines_removed: u64,
}Expand description
One file change a run made, and how many lines it added and removed (0.18.0).
The counts come from comparing the file’s lines before and after, trimming the common head and tail — not from a minimal diff. A one-line replacement is therefore one added and one removed, and a rewrite of the middle of a file is the size of that middle. It answers “how much did this run change” without the crate carrying a diff algorithm it has no other use for.
use io_harness::{Edit, Store};
// A run writes rows like this itself; recorded by hand here so the example
// needs no model.
store.record_edit(run_id, &Edit::measure(
2,
"edit_file",
"src/parse.rs",
"fn parse() {}\nfn other() {}\n",
"fn parse(s: &str) {}\nfn other() {}\n",
))?;
let edits = store.edits(run_id)?;
assert_eq!(edits[0].path, "src/parse.rs");
// One line out, one line in — the untouched line is not counted as either.
assert_eq!((edits[0].lines_added, edits[0].lines_removed), (1, 1));Fields§
§step: u32The step that made the change.
tool: StringThe tool that made it — write_file or edit_file.
path: StringThe path, as the agent named it (relative to the workspace root).
lines_added: u64Lines present after and not before.
lines_removed: u64Lines present before and not after.
Implementations§
Source§impl Edit
impl Edit
Sourcepub fn measure(step: u32, tool: &str, path: &str, old: &str, new: &str) -> Self
pub fn measure(step: u32, tool: &str, path: &str, old: &str, new: &str) -> Self
The change new makes to old, by common head and tail comparison.
use io_harness::Edit;
// A one-line replacement inside a file: one line out, one line in.
let edit = Edit::measure(1, "edit_file", "a.rs", "fn one() {}\nfn two() {}\n",
"fn one() {}\nfn three() {}\n");
assert_eq!((edit.lines_added, edit.lines_removed), (1, 1));
// A new file is all addition; rewriting a file with what it already held
// is neither, which is the fact a byte-count would have missed.
assert_eq!(Edit::measure(1, "write_file", "b.rs", "", "one\ntwo\n").lines_added, 2);
let same = Edit::measure(1, "write_file", "b.rs", "one\ntwo\n", "one\ntwo\n");
assert_eq!((same.lines_added, same.lines_removed), (0, 0));Trait Implementations§
impl Eq for Edit
impl StructuralPartialEq for Edit
Auto Trait Implementations§
impl Freeze for Edit
impl RefUnwindSafe for Edit
impl Send for Edit
impl Sync for Edit
impl Unpin for Edit
impl UnsafeUnpin for Edit
impl UnwindSafe for Edit
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
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,
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
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.