Skip to content

Commit b314454

Browse files
bbc2bodil
authored andcommitted
Allow index of split_off to equal length of vector
This makes it similar to the primitive slice `split_at` from the standard library (see https://doc.rust-lang.org/std/primitive.slice.html#method.split_at).
1 parent 33418b8 commit b314454

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/vector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ impl<A: Clone> Vector<A> {
776776
/// # }
777777
/// ```
778778
pub fn split_off(&mut self, index: usize) -> Self {
779-
assert!(index < self.len());
779+
assert!(index <= self.len());
780780

781781
let mut local_index = index;
782782

@@ -1832,7 +1832,7 @@ mod test {
18321832

18331833
#[test]
18341834
fn split(ref vec in vec(i32::ANY, 1..2000), split_pos in usize::ANY) {
1835-
let split_index = split_pos % vec.len();
1835+
let split_index = split_pos % (vec.len() + 1);
18361836
let mut left = Vector::from_iter(vec.iter().cloned());
18371837
let right = left.split_off(split_index);
18381838
assert_eq!(left.len(), split_index);

0 commit comments

Comments
 (0)