Skip to content

Commit 4b4f46d

Browse files
committed
---
yaml --- r: 106479 b: refs/heads/try c: e589fcf h: refs/heads/master i: 106477: aaf5ff4 106475: d674e8b 106471: 875cab5 106463: 285789f v: v3
1 parent 112a948 commit 4b4f46d

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
@@ -2,7 +2,7 @@
22
refs/heads/master: b8ef9fd9c9f642ce7b8aed82782a1ed745d08d64
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: b8601a3d8b91ad3b653d143307611f2f5c75617e
5-
refs/heads/try: 197116d7ce7862b21eac6af498a2726d7a1bc3d6
5+
refs/heads/try: e589fcffcc8da46b5949d15284a466d9ed27a003
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/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)