De-mode-ify a few minor libcore modules.
This commit is contained in:
parent
52255f898c
commit
91612dbb7e
13 changed files with 69 additions and 36 deletions
|
@ -1,5 +1,9 @@
|
|||
// -*- rust -*-
|
||||
|
||||
// NB: transitionary, de-mode-ing.
|
||||
#[forbid(deprecated_mode)];
|
||||
#[forbid(deprecated_pattern)];
|
||||
|
||||
//! Boolean logic
|
||||
|
||||
export not, and, or, xor, implies;
|
||||
|
@ -38,11 +42,13 @@ pure fn is_true(v: bool) -> bool { v }
|
|||
pure fn is_false(v: bool) -> bool { !v }
|
||||
|
||||
/// Parse logic value from `s`
|
||||
pure fn from_str(s: ~str) -> option<bool> {
|
||||
match check s {
|
||||
~"true" => some(true),
|
||||
~"false" => some(false),
|
||||
_ => none
|
||||
pure fn from_str(s: &str) -> option<bool> {
|
||||
if s == "true" {
|
||||
some(true)
|
||||
} else if s == "false" {
|
||||
some(false)
|
||||
} else {
|
||||
none
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
//! Operations on shared box types
|
||||
|
||||
// NB: transitionary, de-mode-ing.
|
||||
#[forbid(deprecated_mode)];
|
||||
#[forbid(deprecated_pattern)];
|
||||
|
||||
export ptr_eq;
|
||||
|
||||
pure fn ptr_eq<T>(a: @T, b: @T) -> bool {
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
//! Utilities for manipulating the char type
|
||||
|
||||
// NB: transitionary, de-mode-ing.
|
||||
#[forbid(deprecated_mode)];
|
||||
#[forbid(deprecated_pattern)];
|
||||
|
||||
/*
|
||||
Lu Uppercase_Letter an uppercase letter
|
||||
Ll Lowercase_Letter a lowercase letter
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
// NB: transitionary, de-mode-ing.
|
||||
#[forbid(deprecated_mode)];
|
||||
#[forbid(deprecated_pattern)];
|
||||
|
||||
export c_float;
|
||||
export c_double;
|
||||
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
// NB: transitionary, de-mode-ing.
|
||||
#[forbid(deprecated_mode)];
|
||||
#[forbid(deprecated_pattern)];
|
||||
|
||||
/// Interfaces used for comparison.
|
||||
|
||||
trait ord {
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
// NB: transitionary, de-mode-ing.
|
||||
#[forbid(deprecated_mode)];
|
||||
#[forbid(deprecated_pattern)];
|
||||
|
||||
/**
|
||||
* A doubly-linked list. Supports O(1) head, tail, count, push, pop, etc.
|
||||
*
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
// NB: transitionary, de-mode-ing.
|
||||
#[forbid(deprecated_mode)];
|
||||
#[forbid(deprecated_pattern)];
|
||||
|
||||
// Dynamic Vector
|
||||
//
|
||||
// A growable vector that makes use of unique pointers so that the
|
||||
|
@ -69,7 +73,7 @@ fn from_vec<A>(+v: ~[mut A]) -> dvec<A> {
|
|||
}
|
||||
|
||||
/// Consumes the vector and returns its contents
|
||||
fn unwrap<A>(-d: dvec<A>) -> ~[mut A] {
|
||||
fn unwrap<A>(+d: dvec<A>) -> ~[mut A] {
|
||||
let dvec_({data: v}) <- d;
|
||||
return v;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
// NB: transitionary, de-mode-ing.
|
||||
#[forbid(deprecated_mode)];
|
||||
#[forbid(deprecated_pattern)];
|
||||
|
||||
//! A type that represents one of two alternatives
|
||||
|
||||
import result::result;
|
||||
|
@ -8,8 +12,8 @@ enum either<T, U> {
|
|||
right(U)
|
||||
}
|
||||
|
||||
fn either<T, U, V>(f_left: fn(T) -> V,
|
||||
f_right: fn(U) -> V, value: either<T, U>) -> V {
|
||||
fn either<T, U, V>(f_left: fn((&T)) -> V,
|
||||
f_right: fn((&U)) -> V, value: &either<T, U>) -> V {
|
||||
/*!
|
||||
* Applies a function based on the given either value
|
||||
*
|
||||
|
@ -18,13 +22,13 @@ fn either<T, U, V>(f_left: fn(T) -> V,
|
|||
* result is returned.
|
||||
*/
|
||||
|
||||
match value {
|
||||
left(l) => f_left(l),
|
||||
right(r) => f_right(r)
|
||||
match *value {
|
||||
left(ref l) => f_left(l),
|
||||
right(ref r) => f_right(r)
|
||||
}
|
||||
}
|
||||
|
||||
fn lefts<T: copy, U>(eithers: ~[either<T, U>]) -> ~[T] {
|
||||
fn lefts<T: copy, U>(eithers: &[either<T, U>]) -> ~[T] {
|
||||
//! Extracts from a vector of either all the left values
|
||||
|
||||
let mut result: ~[T] = ~[];
|
||||
|
@ -37,7 +41,7 @@ fn lefts<T: copy, U>(eithers: ~[either<T, U>]) -> ~[T] {
|
|||
return result;
|
||||
}
|
||||
|
||||
fn rights<T, U: copy>(eithers: ~[either<T, U>]) -> ~[U] {
|
||||
fn rights<T, U: copy>(eithers: &[either<T, U>]) -> ~[U] {
|
||||
//! Extracts from a vector of either all the right values
|
||||
|
||||
let mut result: ~[U] = ~[];
|
||||
|
@ -50,7 +54,7 @@ fn rights<T, U: copy>(eithers: ~[either<T, U>]) -> ~[U] {
|
|||
return result;
|
||||
}
|
||||
|
||||
fn partition<T: copy, U: copy>(eithers: ~[either<T, U>])
|
||||
fn partition<T: copy, U: copy>(eithers: &[either<T, U>])
|
||||
-> {lefts: ~[T], rights: ~[U]} {
|
||||
/*!
|
||||
* Extracts from a vector of either all the left values and right values
|
||||
|
@ -70,17 +74,16 @@ fn partition<T: copy, U: copy>(eithers: ~[either<T, U>])
|
|||
return {lefts: lefts, rights: rights};
|
||||
}
|
||||
|
||||
pure fn flip<T: copy, U: copy>(eith: either<T, U>) -> either<U, T> {
|
||||
pure fn flip<T: copy, U: copy>(eith: &either<T, U>) -> either<U, T> {
|
||||
//! Flips between left and right of a given either
|
||||
|
||||
match eith {
|
||||
match *eith {
|
||||
right(r) => left(r),
|
||||
left(l) => right(l)
|
||||
}
|
||||
}
|
||||
|
||||
pure fn to_result<T: copy, U: copy>(
|
||||
eith: either<T, U>) -> result<U, T> {
|
||||
pure fn to_result<T: copy, U: copy>(eith: &either<T, U>) -> result<U, T> {
|
||||
/*!
|
||||
* Converts either::t to a result::t
|
||||
*
|
||||
|
@ -88,38 +91,38 @@ pure fn to_result<T: copy, U: copy>(
|
|||
* an ok result, and the "left" choice a fail
|
||||
*/
|
||||
|
||||
match eith {
|
||||
match *eith {
|
||||
right(r) => result::ok(r),
|
||||
left(l) => result::err(l)
|
||||
}
|
||||
}
|
||||
|
||||
pure fn is_left<T, U>(eith: either<T, U>) -> bool {
|
||||
pure fn is_left<T, U>(eith: &either<T, U>) -> bool {
|
||||
//! Checks whether the given value is a left
|
||||
|
||||
match eith { left(_) => true, _ => false }
|
||||
match *eith { left(_) => true, _ => false }
|
||||
}
|
||||
|
||||
pure fn is_right<T, U>(eith: either<T, U>) -> bool {
|
||||
pure fn is_right<T, U>(eith: &either<T, U>) -> bool {
|
||||
//! Checks whether the given value is a right
|
||||
|
||||
match eith { right(_) => true, _ => false }
|
||||
match *eith { right(_) => true, _ => false }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_either_left() {
|
||||
let val = left(10);
|
||||
fn f_left(&&x: int) -> bool { x == 10 }
|
||||
fn f_right(&&_x: uint) -> bool { false }
|
||||
assert (either(f_left, f_right, val));
|
||||
fn f_left(x: &int) -> bool { *x == 10 }
|
||||
fn f_right(_x: &uint) -> bool { false }
|
||||
assert (either(f_left, f_right, &val));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_either_right() {
|
||||
let val = right(10u);
|
||||
fn f_left(&&_x: int) -> bool { false }
|
||||
fn f_right(&&x: uint) -> bool { x == 10u }
|
||||
assert (either(f_left, f_right, val));
|
||||
fn f_left(_x: &int) -> bool { false }
|
||||
fn f_right(x: &uint) -> bool { *x == 10u }
|
||||
assert (either(f_left, f_right, &val));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -110,8 +110,8 @@ fn recv_timeout<T: copy send>(iotask: iotask,
|
|||
left_val});
|
||||
none
|
||||
}, |right_val| {
|
||||
some(right_val)
|
||||
}, comm::select2(timeout_po, wait_po)
|
||||
some(*right_val)
|
||||
}, &comm::select2(timeout_po, wait_po)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -297,7 +297,7 @@ fn get_options(ccx: @crate_ctxt, m: match_, col: uint) -> ~[opt] {
|
|||
}
|
||||
}
|
||||
}
|
||||
return vec::from_mut(dvec::unwrap(found));
|
||||
return vec::from_mut(dvec::unwrap(move found));
|
||||
}
|
||||
|
||||
fn extract_variant_args(bcx: block, pat_id: ast::node_id,
|
||||
|
|
|
@ -17,7 +17,7 @@ fn collect_dvec(num: uint) -> ~[mut uint] {
|
|||
for uint::range(0u, num) |i| {
|
||||
result.push(i);
|
||||
}
|
||||
return dvec::unwrap(result);
|
||||
return dvec::unwrap(move result);
|
||||
}
|
||||
|
||||
fn main(args: ~[~str]) {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
// error-pattern:quux
|
||||
fn test00_start(ch: chan_t<int>, message: int) { send(ch, copy message); }
|
||||
fn test00_start(ch: chan_t<int>, message: int) { send(ch, message); }
|
||||
|
||||
type task_id = int;
|
||||
type port_id = int;
|
||||
|
||||
enum chan_t<T: send> = {task: task_id, port: port_id};
|
||||
|
||||
fn send<T: send>(ch: chan_t<T>, -data: T) { fail; }
|
||||
fn send<T: send>(ch: chan_t<T>, data: T) { fail; }
|
||||
|
||||
fn main() { fail ~"quux"; }
|
||||
|
|
|
@ -23,5 +23,5 @@ fn main() {
|
|||
assert e == exp[i];
|
||||
}
|
||||
|
||||
assert dvec::unwrap(d) == exp;
|
||||
assert dvec::unwrap(move d) == exp;
|
||||
}
|
Loading…
Reference in a new issue