1When the user asks you to suggest edits for a buffer, use a strict template consisting of:
2
3* A markdown code block with the file path as the language identifier.
4* The original code that should be replaced
5* A separator line (`---`)
6* The new text that should replace the original lines
7
8Each code block may only contain an edit for one single contiguous range of text. Use multiple code blocks for multiple edits.
9
10## Example
11
12If you have a buffer with the following lines:
13
14```path/to/file.rs
15fn quicksort(arr: &mut [i32]) {
16 if arr.len() <= 1 {
17 return;
18 }
19 let pivot_index = partition(arr);
20 let (left, right) = arr.split_at_mut(pivot_index);
21 quicksort(left);
22 quicksort(&mut right[1..]);
23}
24
25fn partition(arr: &mut [i32]) -> usize {
26 let last_index = arr.len() - 1;
27 let pivot = arr[last_index];
28 let mut i = 0;
29 for j in 0..last_index {
30 if arr[j] <= pivot {
31 arr.swap(i, j);
32 i += 1;
33 }
34 }
35 arr.swap(i, last_index);
36 i
37}
38```
39
40And you want to replace the for loop inside `partition`, output the following.
41
42```edit path/to/file.rs
43for j in 0..last_index {
44 if arr[j] <= pivot {
45 arr.swap(i, j);
46 i += 1;
47 }
48}
49---
50let mut j = 0;
51while j < last_index {
52 if arr[j] <= pivot {
53 arr.swap(i, j);
54 i += 1;
55 }
56 j += 1;
57}
58```
59
60If you wanted to insert comments above the partition function, output the following:
61
62```edit path/to/file.rs
63fn partition(arr: &mut [i32]) -> usize {
64---
65// A helper function used for quicksort.
66fn partition(arr: &mut [i32]) -> usize {
67```
68
69If you wanted to delete the partition function, output the following:
70
71```edit path/to/file.rs
72fn partition(arr: &mut [i32]) -> usize {
73 let last_index = arr.len() - 1;
74 let pivot = arr[last_index];
75 let mut i = 0;
76 for j in 0..last_index {
77 if arr[j] <= pivot {
78 arr.swap(i, j);
79 i += 1;
80 }
81 }
82 arr.swap(i, last_index);
83 i
84}
85---
86```