Skip to content

Commit 760977f

Browse files
committed
---
yaml --- r: 102233 b: refs/heads/master c: e589fcf h: refs/heads/master i: 102231: 7c6e0cf v: v3
1 parent a0a1ea6 commit 760977f

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 197116d7ce7862b21eac6af498a2726d7a1bc3d6
2+
refs/heads/master: e589fcffcc8da46b5949d15284a466d9ed27a003
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6e7f170fedd3c526a643c0b2d13863acd982be02
55
refs/heads/try: a97642026c18a624ff6ea01075dd9550f8ed07ff

trunk/src/libcollections/list.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
//! A standard, garbage-collected linked list.
1212
13+
use std::container::Container;
14+
1315
#[deriving(Clone, Eq)]
1416
#[allow(missing_doc)]
1517
pub enum List<T> {
@@ -53,6 +55,11 @@ impl<T> List<T> {
5355
}
5456
}
5557

58+
impl<T> Container for List<T> {
59+
/// Returns the length of a list
60+
fn len(&self) -> uint { self.iter().len() }
61+
}
62+
5663
/// Returns true if a list contains an element with the given value
5764
pub fn has<T:Eq>(list: @List<T>, element: T) -> bool {
5865
let mut found = false;
@@ -70,13 +77,6 @@ pub fn is_empty<T>(list: @List<T>) -> bool {
7077
}
7178
}
7279

73-
/// Returns the length of a list
74-
pub fn len<T>(list: @List<T>) -> uint {
75-
let mut count = 0u;
76-
iter(list, |_e| count += 1u);
77-
count
78-
}
79-
8080
/// Returns all but the first element of a list
8181
pub fn tail<T>(list: @List<T>) -> @List<T> {
8282
match *list {
@@ -252,10 +252,11 @@ mod tests {
252252

253253
#[test]
254254
fn test_len() {
255-
let list = @List::from_vec([0, 1, 2]);
256-
let empty = @list::Nil::<int>;
257-
assert_eq!(list::len(list), 3u);
258-
assert_eq!(list::len(empty), 0u);
255+
let empty = Nil::<int>;
256+
assert_eq!(empty.len(), 0u);
257+
258+
let list = List::from_vec([0, 1, 2]);
259+
assert_eq!(list.len(), 3u);
259260
}
260261

261262
#[test]

0 commit comments

Comments
 (0)