Skip to content

Commit e75d0a9

Browse files
committed
[std::vec] Rename .remove_opt() to .remove(), drop the old .remove() behavior
1 parent b5e6573 commit e75d0a9

File tree

4 files changed

+16
-50
lines changed

4 files changed

+16
-50
lines changed

src/libextra/treemap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ mod test_treemap {
11641164

11651165
30.times(|| {
11661166
let r = rng.gen_range(0, ctrl.len());
1167-
let (key, _) = ctrl.remove(r);
1167+
let (key, _) = ctrl.remove(r).unwrap();
11681168
assert!(map.remove(&key));
11691169
check_structure(&map);
11701170
check_equal(ctrl, &map);

src/libgreen/basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl BasicLoop {
8484
}
8585
RemoveRemote(i) => {
8686
match self.remotes.iter().position(|&(id, _)| id == i) {
87-
Some(i) => { self.remotes.remove(i); }
87+
Some(i) => { self.remotes.remove(i).unwrap(); }
8888
None => unreachable!()
8989
}
9090
}

src/libstd/sync/deque.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl<T: Send> BufferPool<T> {
157157
unsafe {
158158
self.pool.with(|pool| {
159159
match pool.iter().position(|x| x.size() >= (1 << bits)) {
160-
Some(i) => pool.remove(i),
160+
Some(i) => pool.remove(i).unwrap(),
161161
None => ~Buffer::new(bits)
162162
}
163163
})

src/libstd/vec.rs

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,18 +1399,14 @@ pub trait OwnedVector<T> {
13991399
/// # Example
14001400
/// ```rust
14011401
/// let mut v = ~[1, 2, 3];
1402-
/// assert_eq!(v.remove_opt(1), Some(2));
1402+
/// assert_eq!(v.remove(1), Some(2));
14031403
/// assert_eq!(v, ~[1, 3]);
14041404
///
1405-
/// assert_eq!(v.remove_opt(4), None);
1405+
/// assert_eq!(v.remove(4), None);
14061406
/// // v is unchanged:
14071407
/// assert_eq!(v, ~[1, 3]);
14081408
/// ```
1409-
fn remove_opt(&mut self, i: uint) -> Option<T>;
1410-
1411-
/// Remove and return the element at position i within v, shifting
1412-
/// all elements after position i one position to the left.
1413-
fn remove(&mut self, i: uint) -> T;
1409+
fn remove(&mut self, i: uint) -> Option<T>;
14141410

14151411
/**
14161412
* Remove an element from anywhere in the vector and return it, replacing it
@@ -1577,7 +1573,7 @@ impl<T> OwnedVector<T> for ~[T] {
15771573

15781574
#[inline]
15791575
fn shift(&mut self) -> Option<T> {
1580-
self.remove_opt(0)
1576+
self.remove(0)
15811577
}
15821578

15831579
#[inline]
@@ -1604,15 +1600,7 @@ impl<T> OwnedVector<T> for ~[T] {
16041600
}
16051601
}
16061602

1607-
#[inline]
1608-
fn remove(&mut self, i: uint) -> T {
1609-
match self.remove_opt(i) {
1610-
Some(t) => t,
1611-
None => fail!("remove: the len is {} but the index is {}", self.len(), i)
1612-
}
1613-
}
1614-
1615-
fn remove_opt(&mut self, i: uint) -> Option<T> {
1603+
fn remove(&mut self, i: uint) -> Option<T> {
16161604
let len = self.len();
16171605
if i < len {
16181606
unsafe { // infallible
@@ -3617,48 +3605,26 @@ mod tests {
36173605
}
36183606

36193607
#[test]
3620-
fn test_remove_opt() {
3608+
fn test_remove() {
36213609
let mut a = ~[1,2,3,4];
36223610

3623-
assert_eq!(a.remove_opt(2), Some(3));
3611+
assert_eq!(a.remove(2), Some(3));
36243612
assert_eq!(a, ~[1,2,4]);
36253613

3626-
assert_eq!(a.remove_opt(2), Some(4));
3614+
assert_eq!(a.remove(2), Some(4));
36273615
assert_eq!(a, ~[1,2]);
36283616

3629-
assert_eq!(a.remove_opt(2), None);
3617+
assert_eq!(a.remove(2), None);
36303618
assert_eq!(a, ~[1,2]);
36313619

3632-
assert_eq!(a.remove_opt(0), Some(1));
3620+
assert_eq!(a.remove(0), Some(1));
36333621
assert_eq!(a, ~[2]);
36343622

3635-
assert_eq!(a.remove_opt(0), Some(2));
3623+
assert_eq!(a.remove(0), Some(2));
36363624
assert_eq!(a, ~[]);
36373625

3638-
assert_eq!(a.remove_opt(0), None);
3639-
assert_eq!(a.remove_opt(10), None);
3640-
}
3641-
3642-
#[test]
3643-
fn test_remove() {
3644-
let mut a = ~[1, 2, 3, 4];
3645-
a.remove(2);
3646-
assert_eq!(a, ~[1, 2, 4]);
3647-
3648-
let mut a = ~[1, 2, 3];
3649-
a.remove(0);
3650-
assert_eq!(a, ~[2, 3]);
3651-
3652-
let mut a = ~[1];
3653-
a.remove(0);
3654-
assert_eq!(a, ~[]);
3655-
}
3656-
3657-
#[test]
3658-
#[should_fail]
3659-
fn test_remove_oob() {
3660-
let mut a = ~[1, 2, 3];
3661-
a.remove(3);
3626+
assert_eq!(a.remove(0), None);
3627+
assert_eq!(a.remove(10), None);
36623628
}
36633629

36643630
#[test]

0 commit comments

Comments
 (0)