Skip to content

Commit 47eb0e8

Browse files
committed
Add CodeFix::apply_solution and impl Clone
1 parent 06daef6 commit 47eb0e8

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rustfix/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustfix"
3-
version = "0.8.4"
3+
version = "0.8.5"
44
authors = [
55
"Pascal Hertleif <[email protected]>",
66
"Oliver Schneider <[email protected]>",

crates/rustfix/src/lib.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ pub fn collect_suggestions<S: ::std::hash::BuildHasher>(
213213
/// 1. Feeds the source of a file to [`CodeFix::new`].
214214
/// 2. Calls [`CodeFix::apply`] to apply suggestions to the source code.
215215
/// 3. Calls [`CodeFix::finish`] to get the "fixed" code.
216+
#[derive(Clone)]
216217
pub struct CodeFix {
217218
data: replace::Data,
218219
/// Whether or not the data has been modified.
@@ -230,12 +231,18 @@ impl CodeFix {
230231

231232
/// Applies a suggestion to the code.
232233
pub fn apply(&mut self, suggestion: &Suggestion) -> Result<(), Error> {
233-
for sol in &suggestion.solutions {
234-
for r in &sol.replacements {
235-
self.data
236-
.replace_range(r.snippet.range.clone(), r.replacement.as_bytes())?;
237-
self.modified = true;
238-
}
234+
for solution in &suggestion.solutions {
235+
self.apply_solution(solution)?;
236+
}
237+
Ok(())
238+
}
239+
240+
/// Applies an individual solution from a [`Suggestion`]
241+
pub fn apply_solution(&mut self, solution: &Solution) -> Result<(), Error> {
242+
for r in &solution.replacements {
243+
self.data
244+
.replace_range(r.snippet.range.clone(), r.replacement.as_bytes())?;
245+
self.modified = true;
239246
}
240247
Ok(())
241248
}

0 commit comments

Comments
 (0)