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 -*-
|
// -*- rust -*-
|
||||||
|
|
||||||
|
// NB: transitionary, de-mode-ing.
|
||||||
|
#[forbid(deprecated_mode)];
|
||||||
|
#[forbid(deprecated_pattern)];
|
||||||
|
|
||||||
//! Boolean logic
|
//! Boolean logic
|
||||||
|
|
||||||
export not, and, or, xor, implies;
|
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 }
|
pure fn is_false(v: bool) -> bool { !v }
|
||||||
|
|
||||||
/// Parse logic value from `s`
|
/// Parse logic value from `s`
|
||||||
pure fn from_str(s: ~str) -> option<bool> {
|
pure fn from_str(s: &str) -> option<bool> {
|
||||||
match check s {
|
if s == "true" {
|
||||||
~"true" => some(true),
|
some(true)
|
||||||
~"false" => some(false),
|
} else if s == "false" {
|
||||||
_ => none
|
some(false)
|
||||||
|
} else {
|
||||||
|
none
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
//! Operations on shared box types
|
//! Operations on shared box types
|
||||||
|
|
||||||
|
// NB: transitionary, de-mode-ing.
|
||||||
|
#[forbid(deprecated_mode)];
|
||||||
|
#[forbid(deprecated_pattern)];
|
||||||
|
|
||||||
export ptr_eq;
|
export ptr_eq;
|
||||||
|
|
||||||
pure fn ptr_eq<T>(a: @T, b: @T) -> bool {
|
pure fn ptr_eq<T>(a: @T, b: @T) -> bool {
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
//! Utilities for manipulating the char type
|
//! Utilities for manipulating the char type
|
||||||
|
|
||||||
|
// NB: transitionary, de-mode-ing.
|
||||||
|
#[forbid(deprecated_mode)];
|
||||||
|
#[forbid(deprecated_pattern)];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Lu Uppercase_Letter an uppercase letter
|
Lu Uppercase_Letter an uppercase letter
|
||||||
Ll Lowercase_Letter a lowercase 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_float;
|
||||||
export c_double;
|
export c_double;
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
// NB: transitionary, de-mode-ing.
|
||||||
|
#[forbid(deprecated_mode)];
|
||||||
|
#[forbid(deprecated_pattern)];
|
||||||
|
|
||||||
/// Interfaces used for comparison.
|
/// Interfaces used for comparison.
|
||||||
|
|
||||||
trait ord {
|
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.
|
* 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
|
// Dynamic Vector
|
||||||
//
|
//
|
||||||
// A growable vector that makes use of unique pointers so that the
|
// 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
|
/// 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;
|
let dvec_({data: v}) <- d;
|
||||||
return v;
|
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
|
//! A type that represents one of two alternatives
|
||||||
|
|
||||||
import result::result;
|
import result::result;
|
||||||
|
@ -8,8 +12,8 @@ enum either<T, U> {
|
||||||
right(U)
|
right(U)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn either<T, U, V>(f_left: fn(T) -> V,
|
fn either<T, U, V>(f_left: fn((&T)) -> V,
|
||||||
f_right: fn(U) -> V, value: either<T, U>) -> V {
|
f_right: fn((&U)) -> V, value: &either<T, U>) -> V {
|
||||||
/*!
|
/*!
|
||||||
* Applies a function based on the given either value
|
* 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.
|
* result is returned.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
match value {
|
match *value {
|
||||||
left(l) => f_left(l),
|
left(ref l) => f_left(l),
|
||||||
right(r) => f_right(r)
|
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
|
//! Extracts from a vector of either all the left values
|
||||||
|
|
||||||
let mut result: ~[T] = ~[];
|
let mut result: ~[T] = ~[];
|
||||||
|
@ -37,7 +41,7 @@ fn lefts<T: copy, U>(eithers: ~[either<T, U>]) -> ~[T] {
|
||||||
return result;
|
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
|
//! Extracts from a vector of either all the right values
|
||||||
|
|
||||||
let mut result: ~[U] = ~[];
|
let mut result: ~[U] = ~[];
|
||||||
|
@ -50,7 +54,7 @@ fn rights<T, U: copy>(eithers: ~[either<T, U>]) -> ~[U] {
|
||||||
return result;
|
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]} {
|
-> {lefts: ~[T], rights: ~[U]} {
|
||||||
/*!
|
/*!
|
||||||
* Extracts from a vector of either all the left values and right values
|
* 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};
|
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
|
//! Flips between left and right of a given either
|
||||||
|
|
||||||
match eith {
|
match *eith {
|
||||||
right(r) => left(r),
|
right(r) => left(r),
|
||||||
left(l) => right(l)
|
left(l) => right(l)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn to_result<T: copy, U: copy>(
|
pure fn to_result<T: copy, U: copy>(eith: &either<T, U>) -> result<U, T> {
|
||||||
eith: either<T, U>) -> result<U, T> {
|
|
||||||
/*!
|
/*!
|
||||||
* Converts either::t to a result::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
|
* an ok result, and the "left" choice a fail
|
||||||
*/
|
*/
|
||||||
|
|
||||||
match eith {
|
match *eith {
|
||||||
right(r) => result::ok(r),
|
right(r) => result::ok(r),
|
||||||
left(l) => result::err(l)
|
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
|
//! 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
|
//! Checks whether the given value is a right
|
||||||
|
|
||||||
match eith { right(_) => true, _ => false }
|
match *eith { right(_) => true, _ => false }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_either_left() {
|
fn test_either_left() {
|
||||||
let val = left(10);
|
let val = left(10);
|
||||||
fn f_left(&&x: int) -> bool { x == 10 }
|
fn f_left(x: &int) -> bool { *x == 10 }
|
||||||
fn f_right(&&_x: uint) -> bool { false }
|
fn f_right(_x: &uint) -> bool { false }
|
||||||
assert (either(f_left, f_right, val));
|
assert (either(f_left, f_right, &val));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_either_right() {
|
fn test_either_right() {
|
||||||
let val = right(10u);
|
let val = right(10u);
|
||||||
fn f_left(&&_x: int) -> bool { false }
|
fn f_left(_x: &int) -> bool { false }
|
||||||
fn f_right(&&x: uint) -> bool { x == 10u }
|
fn f_right(x: &uint) -> bool { *x == 10u }
|
||||||
assert (either(f_left, f_right, val));
|
assert (either(f_left, f_right, &val));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -110,8 +110,8 @@ fn recv_timeout<T: copy send>(iotask: iotask,
|
||||||
left_val});
|
left_val});
|
||||||
none
|
none
|
||||||
}, |right_val| {
|
}, |right_val| {
|
||||||
some(right_val)
|
some(*right_val)
|
||||||
}, comm::select2(timeout_po, wait_po)
|
}, &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,
|
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| {
|
for uint::range(0u, num) |i| {
|
||||||
result.push(i);
|
result.push(i);
|
||||||
}
|
}
|
||||||
return dvec::unwrap(result);
|
return dvec::unwrap(move result);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main(args: ~[~str]) {
|
fn main(args: ~[~str]) {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
// error-pattern:quux
|
// 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 task_id = int;
|
||||||
type port_id = int;
|
type port_id = int;
|
||||||
|
|
||||||
enum chan_t<T: send> = {task: task_id, port: port_id};
|
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"; }
|
fn main() { fail ~"quux"; }
|
||||||
|
|
|
@ -23,5 +23,5 @@ fn main() {
|
||||||
assert e == exp[i];
|
assert e == exp[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
assert dvec::unwrap(d) == exp;
|
assert dvec::unwrap(move d) == exp;
|
||||||
}
|
}
|
Loading…
Reference in a new issue