Skip to content

Commit cc42211

Browse files
author
Isaac Aggrey
committed
---
yaml --- r: 36822 b: refs/heads/try2 c: 63232d6 h: refs/heads/master v: v3
1 parent 0b02fdb commit cc42211

File tree

11 files changed

+106
-262
lines changed

11 files changed

+106
-262
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: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 2ad41b881cb8389cb690c643e41c27f6c34270d5
8+
refs/heads/try2: 63232d6cf16ea2c4503b580c23a9fe8e31671a0d
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try2/doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1924,7 +1924,7 @@ types by the compiler, and may not be overridden:
19241924
19251925
Additionally, the `Drop` trait is used to define destructors. This
19261926
trait defines one method called `finalize`, which is automatically
1927-
called when value of the a type that implements this trait is
1927+
called when a value of the type that implements this trait is
19281928
destroyed, either because the value went out of scope or because the
19291929
garbage collector reclaimed it.
19301930

branches/try2/src/libcore/dvec.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ priv impl<A> DVec<A> {
110110
self.data = move data;
111111
}
112112
}
113-
114-
#[inline(always)]
115-
fn unwrap(self) -> ~[A] { unwrap(self) }
116113
}
117114

118115
// In theory, most everything should work with any A, but in practice

branches/try2/src/libcore/either.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,6 @@ pub pure fn unwrap_right<T,U>(eith: Either<T,U>) -> U {
142142
}
143143
}
144144

145-
impl<T, U> Either<T, U> {
146-
#[inline(always)]
147-
fn unwrap_left(self) -> T { unwrap_left(self) }
148-
149-
#[inline(always)]
150-
fn unwrap_right(self) -> U { unwrap_right(self) }
151-
}
152-
153145
#[test]
154146
fn test_either_left() {
155147
let val = Left(10);

branches/try2/src/libcore/mutable.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ impl<T> Data<T> {
7373
op(unsafe{transmute_immut(&mut self.value)})
7474
}
7575
}
76-
77-
#[inline(always)]
78-
fn unwrap(self) -> T { unwrap(self) }
7976
}
8077

8178
#[test]

branches/try2/src/libcore/option.rs

Lines changed: 40 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ pub pure fn get_ref<T>(opt: &r/Option<T>) -> &r/T {
9696
}
9797
}
9898

99+
pub pure fn expect<T>(opt: Option<T>, reason: ~str) -> T {
100+
/*!
101+
* Gets the value out of an option without copying, printing a
102+
* specified message on failure.
103+
*
104+
* # Failure
105+
*
106+
* Fails if the value equals `none`
107+
*/
108+
if opt.is_some() { move option::unwrap(move opt) }
109+
else { fail reason }
110+
}
111+
99112
pub pure fn map<T, U>(opt: &Option<T>, f: fn(x: &T) -> U) -> Option<U> {
100113
//! Maps a `some` value by reference from one type to another
101114
@@ -222,46 +235,35 @@ pub fn swap_unwrap<T>(opt: &mut Option<T>) -> T {
222235
unwrap(util::replace(opt, None))
223236
}
224237

225-
pub pure fn expect<T>(opt: Option<T>, reason: &str) -> T {
238+
pub pure fn unwrap_expect<T>(opt: Option<T>, reason: &str) -> T {
226239
//! As unwrap, but with a specified failure message.
227-
match move opt {
228-
Some(move val) => val,
229-
None => fail reason.to_owned(),
230-
}
240+
if opt.is_none() { fail reason.to_owned(); }
241+
unwrap(move opt)
231242
}
232243

244+
// Some of these should change to be &Option<T>, some should not. See below.
233245
impl<T> Option<T> {
234246
/// Returns true if the option equals `none`
235-
#[inline(always)]
236-
pure fn is_none(&self) -> bool { is_none(self) }
237-
247+
pure fn is_none() -> bool { is_none(&self) }
238248
/// Returns true if the option contains some value
239-
#[inline(always)]
240-
pure fn is_some(&self) -> bool { is_some(self) }
249+
pure fn is_some() -> bool { is_some(&self) }
250+
}
241251

252+
impl<T> &Option<T> {
242253
/**
243254
* Update an optional value by optionally running its content by reference
244255
* through a function that returns an option.
245256
*/
246-
#[inline(always)]
247-
pure fn chain_ref<U>(&self, f: fn(x: &T) -> Option<U>) -> Option<U> {
257+
pure fn chain_ref<U>(f: fn(x: &T) -> Option<U>) -> Option<U> {
248258
chain_ref(self, f)
249259
}
250-
251-
/// Maps a `some` value from one type to another by reference
252-
#[inline(always)]
253-
pure fn map<U>(&self, f: fn(x: &T) -> U) -> Option<U> { map(self, f) }
254-
255260
/// Applies a function to the contained value or returns a default
256-
#[inline(always)]
257-
pure fn map_default<U>(&self, def: U, f: fn(x: &T) -> U) -> U {
258-
map_default(self, move def, f)
259-
}
260-
261+
pure fn map_default<U>(def: U, f: fn(x: &T) -> U) -> U
262+
{ map_default(self, move def, f) }
261263
/// Performs an operation on the contained value by reference
262-
#[inline(always)]
263-
pure fn iter(&self, f: fn(x: &T)) { iter(self, f) }
264-
264+
pure fn iter(f: fn(x: &T)) { iter(self, f) }
265+
/// Maps a `some` value from one type to another by reference
266+
pure fn map<U>(f: fn(x: &T) -> U) -> Option<U> { map(self, f) }
265267
/**
266268
Gets an immutable reference to the value inside an option.
267269
@@ -276,29 +278,7 @@ impl<T> Option<T> {
276278
Instead, prefer to use pattern matching and handle the `None`
277279
case explicitly.
278280
*/
279-
#[inline(always)]
280-
pure fn get_ref(&self) -> &self/T { get_ref(self) }
281-
282-
/**
283-
* Gets the value out of an option without copying.
284-
*
285-
* # Failure
286-
*
287-
* Fails if the value equals `none`
288-
*/
289-
#[inline(always)]
290-
pure fn unwrap(self) -> T { unwrap(self) }
291-
292-
/**
293-
* Gets the value out of an option, printing a specified message on
294-
* failure
295-
*
296-
* # Failure
297-
*
298-
* Fails if the value equals `none`
299-
*/
300-
#[inline(always)]
301-
pure fn expect(self, reason: &str) -> T { expect(self, reason) }
281+
pure fn get_ref() -> &self/T { get_ref(self) }
302282
}
303283

304284
impl<T: Copy> Option<T> {
@@ -316,17 +296,19 @@ impl<T: Copy> Option<T> {
316296
Instead, prefer to use pattern matching and handle the `None`
317297
case explicitly.
318298
*/
319-
#[inline(always)]
320-
pure fn get(self) -> T { get(self) }
321-
322-
#[inline(always)]
323-
pure fn get_default(self, def: T) -> T { get_default(self, def) }
324-
299+
pure fn get() -> T { get(self) }
300+
pure fn get_default(def: T) -> T { get_default(self, def) }
301+
/**
302+
* Gets the value out of an option, printing a specified message on
303+
* failure
304+
*
305+
* # Failure
306+
*
307+
* Fails if the value equals `none`
308+
*/
309+
pure fn expect(reason: ~str) -> T { expect(self, move reason) }
325310
/// Applies a function zero or more times until the result is none.
326-
#[inline(always)]
327-
pure fn while_some(self, blk: fn(v: T) -> Option<T>) {
328-
while_some(self, blk)
329-
}
311+
pure fn while_some(blk: fn(v: T) -> Option<T>) { while_some(self, blk) }
330312
}
331313

332314
#[test]

branches/try2/src/libcore/pipes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ Fails if the sender closes the connection.
412412
*/
413413
pub fn recv<T: Owned, Tbuffer: Owned>(
414414
p: RecvPacketBuffered<T, Tbuffer>) -> T {
415-
try_recv(move p).expect("connection closed")
415+
option::unwrap_expect(try_recv(move p), "connection closed")
416416
}
417417

418418
/** Attempts to receive a message from a pipe.
@@ -1102,7 +1102,7 @@ impl<T: Owned> PortSet<T> : GenericPort<T> {
11021102
}
11031103

11041104
fn recv() -> T {
1105-
self.try_recv().expect("port_set: endpoints closed")
1105+
option::unwrap_expect(self.try_recv(), "port_set: endpoints closed")
11061106
}
11071107

11081108
}

branches/try2/src/libcore/result.rs

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub pure fn to_either<T: Copy, U: Copy>(res: &Result<U, T>)
114114
* ok(parse_bytes(buf))
115115
* }
116116
*/
117-
pub pure fn chain<T, U, V>(res: Result<T, V>, op: fn(T)
117+
pub fn chain<T, U, V>(res: Result<T, V>, op: fn(t: T)
118118
-> Result<U, V>) -> Result<U, V> {
119119
match move res {
120120
Ok(move t) => op(move t),
@@ -130,7 +130,7 @@ pub pure fn chain<T, U, V>(res: Result<T, V>, op: fn(T)
130130
* immediately returned. This function can be used to pass through a
131131
* successful result while handling an error.
132132
*/
133-
pub pure fn chain_err<T, U, V>(
133+
pub fn chain_err<T, U, V>(
134134
res: Result<T, V>,
135135
op: fn(t: V) -> Result<T, U>)
136136
-> Result<T, U> {
@@ -154,7 +154,7 @@ pub pure fn chain_err<T, U, V>(
154154
* print_buf(buf)
155155
* }
156156
*/
157-
pub pure fn iter<T, E>(res: &Result<T, E>, f: fn(&T)) {
157+
pub fn iter<T, E>(res: &Result<T, E>, f: fn(&T)) {
158158
match *res {
159159
Ok(ref t) => f(t),
160160
Err(_) => ()
@@ -169,7 +169,7 @@ pub pure fn iter<T, E>(res: &Result<T, E>, f: fn(&T)) {
169169
* This function can be used to pass through a successful result while
170170
* handling an error.
171171
*/
172-
pub pure fn iter_err<T, E>(res: &Result<T, E>, f: fn(&E)) {
172+
pub fn iter_err<T, E>(res: &Result<T, E>, f: fn(&E)) {
173173
match *res {
174174
Ok(_) => (),
175175
Err(ref e) => f(e)
@@ -190,7 +190,7 @@ pub pure fn iter_err<T, E>(res: &Result<T, E>, f: fn(&E)) {
190190
* parse_bytes(buf)
191191
* }
192192
*/
193-
pub pure fn map<T, E: Copy, U: Copy>(res: &Result<T, E>, op: fn(&T) -> U)
193+
pub fn map<T, E: Copy, U: Copy>(res: &Result<T, E>, op: fn(&T) -> U)
194194
-> Result<U, E> {
195195
match *res {
196196
Ok(ref t) => Ok(op(t)),
@@ -206,7 +206,7 @@ pub pure fn map<T, E: Copy, U: Copy>(res: &Result<T, E>, op: fn(&T) -> U)
206206
* is immediately returned. This function can be used to pass through a
207207
* successful result while handling an error.
208208
*/
209-
pub pure fn map_err<T: Copy, E, F: Copy>(res: &Result<T, E>, op: fn(&E) -> F)
209+
pub fn map_err<T: Copy, E, F: Copy>(res: &Result<T, E>, op: fn(&E) -> F)
210210
-> Result<T, F> {
211211
match *res {
212212
Ok(copy t) => Ok(t),
@@ -215,55 +215,58 @@ pub pure fn map_err<T: Copy, E, F: Copy>(res: &Result<T, E>, op: fn(&E) -> F)
215215
}
216216

217217
impl<T, E> Result<T, E> {
218-
#[inline(always)]
219218
pure fn get_ref(&self) -> &self/T { get_ref(self) }
220219

221-
#[inline(always)]
222-
pure fn is_ok(&self) -> bool { is_ok(self) }
220+
pure fn is_ok() -> bool { is_ok(&self) }
223221

224-
#[inline(always)]
225-
pure fn is_err(&self) -> bool { is_err(self) }
222+
pure fn is_err() -> bool { is_err(&self) }
226223

227-
#[inline(always)]
228-
pure fn iter(&self, f: fn(&T)) { iter(self, f) }
229-
230-
#[inline(always)]
231-
pure fn iter_err(&self, f: fn(&E)) { iter_err(self, f) }
232-
233-
#[inline(always)]
234-
pure fn unwrap(self) -> T { unwrap(self) }
235-
236-
#[inline(always)]
237-
pure fn unwrap_err(self) -> T { unwrap(self) }
238-
239-
#[inline(always)]
240-
pure fn chain<U>(self, op: fn(T) -> Result<U,E>) -> Result<U,E> {
241-
chain(self, op)
224+
pure fn iter(f: fn(&T)) {
225+
match self {
226+
Ok(ref t) => f(t),
227+
Err(_) => ()
228+
}
242229
}
243230

244-
#[inline(always)]
245-
pure fn chain_err<F>(self, op: fn(E) -> Result<T,F>) -> Result<T,F> {
246-
chain_err(self, op)
231+
fn iter_err(f: fn(&E)) {
232+
match self {
233+
Ok(_) => (),
234+
Err(ref e) => f(e)
235+
}
247236
}
248237
}
249238

250239
impl<T: Copy, E> Result<T, E> {
251-
#[inline(always)]
252-
pure fn get(&self) -> T { get(self) }
240+
pure fn get() -> T { get(&self) }
253241

254-
#[inline(always)]
255-
pure fn map_err<F:Copy>(&self, op: fn(&E) -> F) -> Result<T,F> {
256-
map_err(self, op)
242+
fn map_err<F:Copy>(op: fn(&E) -> F) -> Result<T,F> {
243+
match self {
244+
Ok(copy t) => Ok(t),
245+
Err(ref e) => Err(op(e))
246+
}
257247
}
258248
}
259249

260250
impl<T, E: Copy> Result<T, E> {
261-
#[inline(always)]
262-
pure fn get_err(&self) -> E { get_err(self) }
251+
pure fn get_err() -> E { get_err(&self) }
252+
253+
fn map<U:Copy>(op: fn(&T) -> U) -> Result<U,E> {
254+
match self {
255+
Ok(ref t) => Ok(op(t)),
256+
Err(copy e) => Err(e)
257+
}
258+
}
259+
}
260+
261+
impl<T: Copy, E: Copy> Result<T, E> {
262+
fn chain<U:Copy>(op: fn(t: T) -> Result<U,E>) -> Result<U,E> {
263+
// XXX: Bad copy
264+
chain(copy self, op)
265+
}
263266

264-
#[inline(always)]
265-
pure fn map<U:Copy>(&self, op: fn(&T) -> U) -> Result<U,E> {
266-
map(self, op)
267+
fn chain_err<F:Copy>(op: fn(t: E) -> Result<T,F>) -> Result<T,F> {
268+
// XXX: Bad copy
269+
chain_err(copy self, op)
267270
}
268271
}
269272

@@ -357,17 +360,15 @@ pub fn iter_vec2<S,T,U:Copy>(ss: &[S], ts: &[T],
357360
}
358361

359362
/// Unwraps a result, assuming it is an `ok(T)`
360-
#[inline(always)]
361-
pub pure fn unwrap<T, U>(res: Result<T, U>) -> T {
363+
pub fn unwrap<T, U>(res: Result<T, U>) -> T {
362364
match move res {
363365
Ok(move t) => move t,
364366
Err(_) => fail ~"unwrap called on an err result"
365367
}
366368
}
367369

368370
/// Unwraps a result, assuming it is an `err(U)`
369-
#[inline(always)]
370-
pub pure fn unwrap_err<T, U>(res: Result<T, U>) -> U {
371+
pub fn unwrap_err<T, U>(res: Result<T, U>) -> U {
371372
match move res {
372373
Err(move u) => move u,
373374
Ok(_) => fail ~"unwrap called on an ok result"

0 commit comments

Comments
 (0)