Skip to content

Commit b18375b

Browse files
committed
---
yaml --- r: 155411 b: refs/heads/try2 c: 3be6a2f h: refs/heads/master i: 155409: f6316c8 155407: ac41533 v: v3
1 parent 04c28ae commit b18375b

File tree

7 files changed

+115
-12
lines changed

7 files changed

+115
-12
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: 29c2d3df5269a6538b23d79f56b63903e21e69f4
8+
refs/heads/try2: 3be6a2fba8bc3382df4b5a4f9391d9b2f28de9d1
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/default.rs

Lines changed: 108 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,104 @@
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
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+
//! ```
1283
1384
#![stable]
1485

1586
/// 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+
/// ```
16100
pub trait Default {
17-
/// Return the "default value" for a type.
101+
/// Returns the "default value" for a type.
18102
///
19-
/// # Example
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:
20109
///
21110
/// ```
22111
/// use std::default::Default;
@@ -25,6 +114,22 @@ pub trait Default {
25114
/// let (x, y): (Option<String>, f64) = Default::default();
26115
/// let (a, b, (c, d)): (int, uint, (bool, bool)) = Default::default();
27116
/// ```
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+
/// ```
28133
fn default() -> Self;
29134
}
30135

branches/try2/src/libcore/iter.rs

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

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

842841
/// 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.
844842
pub trait OrdIterator<A> {
845843
/// Consumes the entire iterator to return the maximum element.
846844
///

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: *mut c_void, len: size_t,
4636+
pub fn send(socket: c_int, buf: *const 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: *mut c_void, len: c_int,
4676+
pub fn send(socket: SOCKET, buf: *const 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.fsync())
306+
self.flush().and_then(|()| self.fd.datasync())
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 *mut libc::c_void,
340+
buf as *const _,
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 *mut libc::c_void,
176+
buf as *const _,
177177
len as libc::size_t,
178178
flags) as i64
179179
};

0 commit comments

Comments
 (0)