Skip to content

Commit 04c28ae

Browse files
committed
---
yaml --- r: 155410 b: refs/heads/try2 c: 29c2d3d h: refs/heads/master v: v3
1 parent f6316c8 commit 04c28ae

File tree

9 files changed

+106
-116
lines changed

9 files changed

+106
-116
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 3f8da69618e9d46d209571cd73686ee0fdc994a8
8+
refs/heads/try2: 29c2d3df5269a6538b23d79f56b63903e21e69f4
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/cmp.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
4040
#![stable]
4141

42-
use option::{Option, Some};
42+
use option::{Option, Some, None};
4343

4444
/// Trait for values that can be compared for equality and inequality.
4545
///
@@ -268,6 +268,32 @@ pub fn max<T: Ord>(v1: T, v2: T) -> T {
268268
if v1 > v2 { v1 } else { v2 }
269269
}
270270

271+
/// Compare and return the minimum of two values if there is one.
272+
///
273+
/// Returns the first argument if the comparison determines them to be equal.
274+
#[inline]
275+
#[experimental]
276+
pub fn partial_min<T: PartialOrd>(v1: T, v2: T) -> Option<T> {
277+
match v1.partial_cmp(&v2) {
278+
Some(Less) | Some(Equal) => Some(v1),
279+
Some(Greater) => Some(v2),
280+
None => None
281+
}
282+
}
283+
284+
/// Compare and return the maximum of two values if there is one.
285+
///
286+
/// Returns the first argument if the comparison determines them to be equal.
287+
#[inline]
288+
#[experimental]
289+
pub fn partial_max<T: PartialOrd>(v1: T, v2: T) -> Option<T> {
290+
match v1.partial_cmp(&v2) {
291+
Some(Less) => Some(v2),
292+
Some(Equal) | Some(Greater) => Some(v1),
293+
None => None
294+
}
295+
}
296+
271297
// Implementation of PartialEq, Eq, PartialOrd and Ord for primitive types
272298
mod impls {
273299
use cmp::{PartialOrd, Ord, PartialEq, Eq, Ordering,

branches/try2/src/libcore/default.rs

Lines changed: 3 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -8,104 +8,15 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! The `Default` trait for types which may have meaningful default values.
12-
//!
13-
//! Sometimes, you want to fall back to some kind of default value, and
14-
//! don't particularly care what it is. This comes up often with `struct`s
15-
//! that define a set of options:
16-
//!
17-
//! ```
18-
//! struct SomeOptions {
19-
//! foo: int,
20-
//! bar: f32,
21-
//! }
22-
//! ```
23-
//!
24-
//! How can we define some default values? You can use `Default`:
25-
//!
26-
//! ```
27-
//! use std::default::Default;
28-
//!
29-
//! #[deriving(Default)]
30-
//! struct SomeOptions {
31-
//! foo: int,
32-
//! bar: f32,
33-
//! }
34-
//!
35-
//!
36-
//! fn main() {
37-
//! let options: SomeOptions = Default::default();
38-
//! }
39-
//! ```
40-
//!
41-
//! Now, you get all of the default values. Rust implements `Default` for various primitives types.
42-
//! If you have your own type, you need to implement `Default` yourself:
43-
//!
44-
//! ```
45-
//! use std::default::Default;
46-
//!
47-
//! enum Kind {
48-
//! A,
49-
//! B,
50-
//! C,
51-
//! }
52-
//!
53-
//! impl Default for Kind {
54-
//! fn default() -> Kind { A }
55-
//! }
56-
//!
57-
//! #[deriving(Default)]
58-
//! struct SomeOptions {
59-
//! foo: int,
60-
//! bar: f32,
61-
//! baz: Kind,
62-
//! }
63-
//!
64-
//!
65-
//! fn main() {
66-
//! let options: SomeOptions = Default::default();
67-
//! }
68-
//! ```
69-
//!
70-
//! If you want to override a particular option, but still retain the other defaults:
71-
//!
72-
//! ```
73-
//! # use std::default::Default;
74-
//! # #[deriving(Default)]
75-
//! # struct SomeOptions {
76-
//! # foo: int,
77-
//! # bar: f32,
78-
//! # }
79-
//! fn main() {
80-
//! let options = SomeOptions { foo: 42, ..Default::default() };
81-
//! }
82-
//! ```
11+
//! The `Default` trait for types which may have meaningful default values
8312
8413
#![stable]
8514

8615
/// A trait that types which have a useful default value should implement.
87-
///
88-
/// A struct can derive default implementations of `Default` for basic types using
89-
/// `#[deriving(Default)]`.
90-
///
91-
/// # Examples
92-
///
93-
/// ```
94-
/// #[deriving(Default)]
95-
/// struct SomeOptions {
96-
/// foo: int,
97-
/// bar: f32,
98-
/// }
99-
/// ```
10016
pub trait Default {
101-
/// Returns the "default value" for a type.
17+
/// Return the "default value" for a type.
10218
///
103-
/// Default values are often some kind of initial value, identity value, or anything else that
104-
/// may make sense as a default.
105-
///
106-
/// # Examples
107-
///
108-
/// Using built-in default values:
19+
/// # Example
10920
///
11021
/// ```
11122
/// use std::default::Default;
@@ -114,22 +25,6 @@ pub trait Default {
11425
/// let (x, y): (Option<String>, f64) = Default::default();
11526
/// let (a, b, (c, d)): (int, uint, (bool, bool)) = Default::default();
11627
/// ```
117-
///
118-
/// Making your own:
119-
///
120-
/// ```
121-
/// use std::default::Default;
122-
///
123-
/// enum Kind {
124-
/// A,
125-
/// B,
126-
/// C,
127-
/// }
128-
///
129-
/// impl Default for Kind {
130-
/// fn default() -> Kind { A }
131-
/// }
132-
/// ```
13328
fn default() -> Self;
13429
}
13530

branches/try2/src/libcore/iter.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,8 @@ impl<A: Add<A, A> + Zero, T: Iterator<A>> AdditiveIterator<A> for T {
811811
}
812812
}
813813

814-
/// A trait for iterators over elements which can be multiplied together.
814+
/// A trait for iterators over elements whose elements can be multiplied
815+
/// together.
815816
pub trait MultiplicativeIterator<A> {
816817
/// Iterates over the entire iterator, multiplying all the elements
817818
///
@@ -839,6 +840,7 @@ impl<A: Mul<A, A> + One, T: Iterator<A>> MultiplicativeIterator<A> for T {
839840
}
840841

841842
/// A trait for iterators over elements which can be compared to one another.
843+
/// The type of each element must ascribe to the `PartialOrd` trait.
842844
pub trait OrdIterator<A> {
843845
/// Consumes the entire iterator to return the maximum element.
844846
///

branches/try2/src/libcoretest/cmp.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
use core::cmp::lexical_ordering;
12+
use core::cmp::{ partial_min, partial_max };
1213

1314
#[test]
1415
fn test_int_totalord() {
@@ -56,6 +57,72 @@ fn test_lexical_ordering() {
5657
}
5758
}
5859

60+
#[test]
61+
fn test_partial_min() {
62+
use core::f64::NAN;
63+
let data_integer = [
64+
// a, b, result
65+
(0i, 0i, Some(0i)),
66+
(1i, 0i, Some(0i)),
67+
(0i, 1i, Some(0i)),
68+
(-1i, 0i, Some(-1i)),
69+
(0i, -1i, Some(-1i))
70+
];
71+
72+
let data_float = [
73+
// a, b, result
74+
(0.0f64, 0.0f64, Some(0.0f64)),
75+
(1.0f64, 0.0f64, Some(0.0f64)),
76+
(0.0f64, 1.0f64, Some(0.0f64)),
77+
(-1.0f64, 0.0f64, Some(-1.0f64)),
78+
(0.0f64, -1.0f64, Some(-1.0f64)),
79+
(NAN, NAN, None),
80+
(NAN, 1.0f64, None),
81+
(1.0f64, NAN, None)
82+
];
83+
84+
for &(a, b, result) in data_integer.iter() {
85+
assert!(partial_min(a, b) == result);
86+
}
87+
88+
for &(a, b, result) in data_float.iter() {
89+
assert!(partial_min(a, b) == result);
90+
}
91+
}
92+
93+
#[test]
94+
fn test_partial_max() {
95+
use core::f64::NAN;
96+
let data_integer = [
97+
// a, b, result
98+
(0i, 0i, Some(0i)),
99+
(1i, 0i, Some(1i)),
100+
(0i, 1i, Some(1i)),
101+
(-1i, 0i, Some(0i)),
102+
(0i, -1i, Some(0i))
103+
];
104+
105+
let data_float = [
106+
// a, b, result
107+
(0.0f64, 0.0f64, Some(0.0f64)),
108+
(1.0f64, 0.0f64, Some(1.0f64)),
109+
(0.0f64, 1.0f64, Some(1.0f64)),
110+
(-1.0f64, 0.0f64, Some(0.0f64)),
111+
(0.0f64, -1.0f64, Some(0.0f64)),
112+
(NAN, NAN, None),
113+
(NAN, 1.0f64, None),
114+
(1.0f64, NAN, None)
115+
];
116+
117+
for &(a, b, result) in data_integer.iter() {
118+
assert!(partial_max(a, b) == result);
119+
}
120+
121+
for &(a, b, result) in data_float.iter() {
122+
assert!(partial_max(a, b) == result);
123+
}
124+
}
125+
59126
#[test]
60127
fn test_user_defined_eq() {
61128
// Our type.

branches/try2/src/liblibc/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4633,7 +4633,7 @@ pub mod funcs {
46334633
option_len: socklen_t) -> c_int;
46344634
pub fn recv(socket: c_int, buf: *mut c_void, len: size_t,
46354635
flags: c_int) -> ssize_t;
4636-
pub fn send(socket: c_int, buf: *const c_void, len: size_t,
4636+
pub fn send(socket: c_int, buf: *mut c_void, len: size_t,
46374637
flags: c_int) -> ssize_t;
46384638
pub fn recvfrom(socket: c_int, buf: *mut c_void, len: size_t,
46394639
flags: c_int, addr: *mut sockaddr,
@@ -4673,7 +4673,7 @@ pub mod funcs {
46734673
pub fn closesocket(socket: SOCKET) -> c_int;
46744674
pub fn recv(socket: SOCKET, buf: *mut c_void, len: c_int,
46754675
flags: c_int) -> c_int;
4676-
pub fn send(socket: SOCKET, buf: *const c_void, len: c_int,
4676+
pub fn send(socket: SOCKET, buf: *mut c_void, len: c_int,
46774677
flags: c_int) -> c_int;
46784678
pub fn recvfrom(socket: SOCKET, buf: *mut c_void, len: c_int,
46794679
flags: c_int, addr: *mut sockaddr,

branches/try2/src/libnative/io/file_unix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl rtio::RtioFileStream for CFile {
303303
self.flush().and_then(|()| self.fd.fsync())
304304
}
305305
fn datasync(&mut self) -> IoResult<()> {
306-
self.flush().and_then(|()| self.fd.datasync())
306+
self.flush().and_then(|()| self.fd.fsync())
307307
}
308308
fn truncate(&mut self, offset: i64) -> IoResult<()> {
309309
self.flush().and_then(|()| self.fd.truncate(offset))

branches/try2/src/libnative/io/net.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ impl rtio::RtioTcpStream for TcpStream {
337337
let dowrite = |nb: bool, buf: *const u8, len: uint| unsafe {
338338
let flags = if nb {c::MSG_DONTWAIT} else {0};
339339
libc::send(fd,
340-
buf as *const _,
340+
buf as *mut libc::c_void,
341341
len as wrlen,
342342
flags) as i64
343343
};

branches/try2/src/libnative/io/pipe_unix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl rtio::RtioPipe for UnixStream {
173173
let dowrite = |nb: bool, buf: *const u8, len: uint| unsafe {
174174
let flags = if nb {c::MSG_DONTWAIT} else {0};
175175
libc::send(fd,
176-
buf as *const _,
176+
buf as *mut libc::c_void,
177177
len as libc::size_t,
178178
flags) as i64
179179
};

0 commit comments

Comments
 (0)