Skip to content

Commit 871ac11

Browse files
committed
---
yaml --- r: 101679 b: refs/heads/master c: 1f245cc h: refs/heads/master i: 101677: 5ca6901 101675: 633a2b6 101671: f9eb12a 101663: 911e3a3 v: v3
1 parent fb43497 commit 871ac11

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
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: 1b969e11881eab81b9364fc4304dfdfcd2da1128
2+
refs/heads/master: 1f245cc7ea72bc8eeddd12cc9f8e753f3ca71910
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6e7f170fedd3c526a643c0b2d13863acd982be02
55
refs/heads/try: a97642026c18a624ff6ea01075dd9550f8ed07ff

trunk/src/libcollections/list.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,26 @@ pub fn find<T:Clone>(ls: @List<T>, f: |&T| -> bool) -> Option<T> {
6363
};
6464
}
6565

66+
/**
67+
* Returns true if a list contains an element that matches a given predicate
68+
*
69+
* Apply function `f` to each element of `ls`, starting from the first.
70+
* When function `f` returns true then it also returns true. If `f` matches no
71+
* elements then false is returned.
72+
*/
73+
pub fn any<T>(ls: @List<T>, f: |&T| -> bool) -> bool {
74+
let mut ls = ls;
75+
loop {
76+
ls = match *ls {
77+
Cons(ref hd, tl) => {
78+
if f(hd) { return true; }
79+
tl
80+
}
81+
Nil => return false
82+
}
83+
};
84+
}
85+
6686
/// Returns true if a list contains an element with the given value
6787
pub fn has<T:Eq>(ls: @List<T>, elt: T) -> bool {
6888
let mut found = false;
@@ -222,6 +242,15 @@ mod tests {
222242
assert_eq!(list::find(empty, match_), option::None::<int>);
223243
}
224244

245+
#[test]
246+
fn test_any() {
247+
fn match_(i: &int) -> bool { return *i == 2; }
248+
let l = from_vec([0, 1, 2]);
249+
let empty = @list::Nil::<int>;
250+
assert_eq!(list::any(l, match_), true);
251+
assert_eq!(list::any(empty, match_), false);
252+
}
253+
225254
#[test]
226255
fn test_has() {
227256
let l = from_vec([5, 8, 6]);

trunk/src/libstd/io/net/ip.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ use iter::Iterator;
1414
use option::{Option, None, Some};
1515
use str::StrSlice;
1616
use to_str::ToStr;
17+
use to_bytes::IterBytes;
1718
use vec::{MutableCloneableVector, ImmutableVector, MutableVector};
1819

1920
pub type Port = u16;
2021

21-
#[deriving(Eq, TotalEq, Clone)]
22+
#[deriving(Eq, TotalEq, Clone, IterBytes)]
2223
pub enum IpAddr {
2324
Ipv4Addr(u8, u8, u8, u8),
2425
Ipv6Addr(u16, u16, u16, u16, u16, u16, u16, u16)
@@ -48,7 +49,7 @@ impl ToStr for IpAddr {
4849
}
4950
}
5051

51-
#[deriving(Eq, TotalEq, Clone)]
52+
#[deriving(Eq, TotalEq, Clone, IterBytes)]
5253
pub struct SocketAddr {
5354
ip: IpAddr,
5455
port: Port,
@@ -339,6 +340,7 @@ impl FromStr for SocketAddr {
339340
mod test {
340341
use prelude::*;
341342
use super::*;
343+
use to_bytes::ToBytes;
342344

343345
#[test]
344346
fn test_from_str_ipv4() {
@@ -441,4 +443,13 @@ mod test {
441443
assert_eq!(Ipv6Addr(8, 9, 10, 11, 12, 13, 14, 15).to_str(), ~"8:9:a:b:c:d:e:f");
442444
}
443445

446+
#[test]
447+
fn ipv4_addr_to_bytes() {
448+
Ipv4Addr(123, 20, 12, 56).to_bytes(true);
449+
}
450+
451+
#[test]
452+
fn socket_addr_to_bytes() {
453+
SocketAddr { ip: Ipv4Addr(1, 2, 3, 4), port: 1234 }.to_bytes(true);
454+
}
444455
}

trunk/src/test/compile-fail/regions-variance-contravariant-use-covariant.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
// variance inference works in the first place.
1616

1717
// This is contravariant with respect to 'a, meaning that
18-
// Contravariant<'foo> <: Contravariant<'static> because
19-
// 'foo <= 'static
18+
// Contravariant<'long> <: Contravariant<'short> iff
19+
// 'short <= 'long
2020
struct Contravariant<'a> {
2121
f: &'a int
2222
}

0 commit comments

Comments
 (0)