Skip to content

Commit 94e42c2

Browse files
committed
collections: Make push_back/pop_back default methods
1 parent 2d79bfa commit 94e42c2

File tree

3 files changed

+18
-38
lines changed

3 files changed

+18
-38
lines changed

src/libcollections/dlist.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -249,29 +249,17 @@ impl<T> Deque<T> for DList<T> {
249249
fn pop_front(&mut self) -> Option<T> {
250250
self.pop_front_node().map(|box Node{value, ..}| value)
251251
}
252+
}
252253

253-
/// Add an element last in the list
254-
///
255-
/// O(1)
256-
#[deprecated = "use the `push` method"]
257-
fn push_back(&mut self, elt: T) {
254+
impl<T> MutableSeq<T> for DList<T> {
255+
fn push(&mut self, elt: T) {
258256
self.push_back_node(box Node::new(elt))
259257
}
260-
261-
/// Remove the last element and return it, or None if the list is empty
262-
///
263-
/// O(1)
264-
#[deprecated = "use the `pop` method"]
265-
fn pop_back(&mut self) -> Option<T> {
258+
fn pop(&mut self) -> Option<T> {
266259
self.pop_back_node().map(|box Node{value, ..}| value)
267260
}
268261
}
269262

270-
impl<T> MutableSeq<T> for DList<T> {
271-
fn push(&mut self, elt: T) { self.push_back(elt) }
272-
fn pop(&mut self) -> Option<T> { self.pop_back() }
273-
}
274-
275263
impl<T> Default for DList<T> {
276264
#[inline]
277265
fn default() -> DList<T> { DList::new() }

src/libcollections/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ pub trait Deque<T> : MutableSeq<T> {
516516
/// assert_eq!(d.front(), Some(&1i));
517517
/// ```
518518
#[deprecated = "use the `push` method"]
519-
fn push_back(&mut self, elt: T);
519+
fn push_back(&mut self, elt: T) { self.push(elt) }
520520

521521
/// Remove the last element and return it, or `None` if the sequence is empty.
522522
///
@@ -534,7 +534,7 @@ pub trait Deque<T> : MutableSeq<T> {
534534
/// assert_eq!(d.pop_back(), None);
535535
/// ```
536536
#[deprecated = "use the `pop` method"]
537-
fn pop_back(&mut self) -> Option<T>;
537+
fn pop_back(&mut self) -> Option<T> { self.pop() }
538538

539539
/// Remove the first element and return it, or `None` if the sequence is empty.
540540
///

src/libcollections/ringbuf.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,6 @@ impl<T> Deque<T> for RingBuf<T> {
8080
result
8181
}
8282

83-
/// Remove and return the last element in the RingBuf, or None if it is empty
84-
#[deprecated = "use the `pop` method"]
85-
fn pop_back(&mut self) -> Option<T> {
86-
if self.nelts > 0 {
87-
self.nelts -= 1;
88-
let hi = self.raw_index(self.nelts);
89-
self.elts.get_mut(hi).take()
90-
} else {
91-
None
92-
}
93-
}
94-
9583
/// Prepend an element to the RingBuf
9684
fn push_front(&mut self, t: T) {
9785
if self.nelts == self.elts.len() {
@@ -103,22 +91,26 @@ impl<T> Deque<T> for RingBuf<T> {
10391
*self.elts.get_mut(self.lo) = Some(t);
10492
self.nelts += 1u;
10593
}
94+
}
10695

107-
/// Append an element to the RingBuf
108-
#[deprecated = "use the `push` method"]
109-
fn push_back(&mut self, t: T) {
96+
impl<T> MutableSeq<T> for RingBuf<T> {
97+
fn push(&mut self, t: T) {
11098
if self.nelts == self.elts.len() {
11199
grow(self.nelts, &mut self.lo, &mut self.elts);
112100
}
113101
let hi = self.raw_index(self.nelts);
114102
*self.elts.get_mut(hi) = Some(t);
115103
self.nelts += 1u;
116104
}
117-
}
118-
119-
impl<T> MutableSeq<T> for RingBuf<T> {
120-
fn push(&mut self, t: T) { self.push_back(t) }
121-
fn pop(&mut self) -> Option<T> { self.pop_back() }
105+
fn pop(&mut self) -> Option<T> {
106+
if self.nelts > 0 {
107+
self.nelts -= 1;
108+
let hi = self.raw_index(self.nelts);
109+
self.elts.get_mut(hi).take()
110+
} else {
111+
None
112+
}
113+
}
122114
}
123115

124116
impl<T> Default for RingBuf<T> {

0 commit comments

Comments
 (0)