core: Make some functions pure
This commit is contained in:
parent
561511e628
commit
844fbd83da
12 changed files with 21 additions and 21 deletions
|
@ -31,11 +31,11 @@ fn range(lo: i16, hi: i16, it: fn(i16)) {
|
|||
}
|
||||
|
||||
#[doc = "Computes the bitwise complement"]
|
||||
fn compl(i: i16) -> i16 {
|
||||
pure fn compl(i: i16) -> i16 {
|
||||
u16::compl(i as u16) as i16
|
||||
}
|
||||
|
||||
#[doc = "Computes the absolute value"]
|
||||
fn abs(i: i16) -> i16 {
|
||||
pure fn abs(i: i16) -> i16 {
|
||||
if negative(i) { -i } else { i }
|
||||
}
|
||||
|
|
|
@ -31,11 +31,11 @@ fn range(lo: i32, hi: i32, it: fn(i32)) {
|
|||
}
|
||||
|
||||
#[doc = "Computes the bitwise complement"]
|
||||
fn compl(i: i32) -> i32 {
|
||||
pure fn compl(i: i32) -> i32 {
|
||||
u32::compl(i as u32) as i32
|
||||
}
|
||||
|
||||
#[doc = "Computes the absolute value"]
|
||||
fn abs(i: i32) -> i32 {
|
||||
pure fn abs(i: i32) -> i32 {
|
||||
if negative(i) { -i } else { i }
|
||||
}
|
||||
|
|
|
@ -31,11 +31,11 @@ fn range(lo: i64, hi: i64, it: fn(i64)) {
|
|||
}
|
||||
|
||||
#[doc = "Computes the bitwise complement"]
|
||||
fn compl(i: i64) -> i64 {
|
||||
pure fn compl(i: i64) -> i64 {
|
||||
u64::compl(i as u64) as i64
|
||||
}
|
||||
|
||||
#[doc = "Computes the absolute value"]
|
||||
fn abs(i: i64) -> i64 {
|
||||
pure fn abs(i: i64) -> i64 {
|
||||
if negative(i) { -i } else { i }
|
||||
}
|
||||
|
|
|
@ -31,11 +31,11 @@ fn range(lo: i8, hi: i8, it: fn(i8)) {
|
|||
}
|
||||
|
||||
#[doc = "Computes the bitwise complement"]
|
||||
fn compl(i: i8) -> i8 {
|
||||
pure fn compl(i: i8) -> i8 {
|
||||
u8::compl(i as u8) as i8
|
||||
}
|
||||
|
||||
#[doc = "Computes the absolute value"]
|
||||
fn abs(i: i8) -> i8 {
|
||||
pure fn abs(i: i8) -> i8 {
|
||||
if negative(i) { -i } else { i }
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ pure fn nonnegative(x: int) -> bool { ret x >= 0; }
|
|||
|
||||
// FIXME: Make sure this works with negative integers.
|
||||
#[doc = "Produce a uint suitable for use in a hash table"]
|
||||
fn hash(x: int) -> uint { ret x as uint; }
|
||||
pure fn hash(x: int) -> uint { ret x as uint; }
|
||||
|
||||
#[doc = "Iterate over the range `[lo..hi)`"]
|
||||
fn range(lo: int, hi: int, it: fn(int)) {
|
||||
|
@ -107,7 +107,7 @@ fn pow(base: int, exponent: uint) -> int {
|
|||
}
|
||||
|
||||
#[doc = "Computes the bitwise complement"]
|
||||
fn compl(i: int) -> int {
|
||||
pure fn compl(i: int) -> int {
|
||||
uint::compl(i as uint) as int
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ Get the value out of a successful result
|
|||
|
||||
If the result is an error
|
||||
"]
|
||||
fn get<T: copy, U>(res: result<T, U>) -> T {
|
||||
pure fn get<T: copy, U>(res: result<T, U>) -> T {
|
||||
alt res {
|
||||
ok(t) { t }
|
||||
err(_) {
|
||||
|
@ -33,7 +33,7 @@ Get the value out of an error result
|
|||
|
||||
If the result is not an error
|
||||
"]
|
||||
fn get_err<T, U: copy>(res: result<T, U>) -> U {
|
||||
pure fn get_err<T, U: copy>(res: result<T, U>) -> U {
|
||||
alt res {
|
||||
err(u) { u }
|
||||
ok(_) {
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
fn first<T:copy, U:copy>(pair: (T, U)) -> T {
|
||||
pure fn first<T:copy, U:copy>(pair: (T, U)) -> T {
|
||||
let (t, _) = pair;
|
||||
ret t;
|
||||
}
|
||||
|
||||
fn second<T:copy, U:copy>(pair: (T, U)) -> U {
|
||||
pure fn second<T:copy, U:copy>(pair: (T, U)) -> U {
|
||||
let (_, u) = pair;
|
||||
ret u;
|
||||
}
|
||||
|
||||
fn swap<T:copy, U:copy>(pair: (T, U)) -> (U, T) {
|
||||
pure fn swap<T:copy, U:copy>(pair: (T, U)) -> (U, T) {
|
||||
let (t, u) = pair;
|
||||
ret (u, t);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,6 @@ fn range(lo: u16, hi: u16, it: fn(u16)) {
|
|||
}
|
||||
|
||||
#[doc = "Computes the bitwise complement"]
|
||||
fn compl(i: u16) -> u16 {
|
||||
pure fn compl(i: u16) -> u16 {
|
||||
max_value ^ i
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ fn range(lo: u32, hi: u32, it: fn(u32)) {
|
|||
}
|
||||
|
||||
#[doc = "Computes the bitwise complement"]
|
||||
fn compl(i: u32) -> u32 {
|
||||
pure fn compl(i: u32) -> u32 {
|
||||
max_value ^ i
|
||||
}
|
||||
|
||||
|
|
|
@ -82,6 +82,6 @@ fn from_str(buf: str, radix: u64) -> option<u64> {
|
|||
}
|
||||
|
||||
#[doc = "Computes the bitwise complement"]
|
||||
fn compl(i: u64) -> u64 {
|
||||
pure fn compl(i: u64) -> u64 {
|
||||
max_value ^ i
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ fn range(lo: u8, hi: u8, it: fn(u8)) {
|
|||
}
|
||||
|
||||
#[doc = "Computes the bitwise complement"]
|
||||
fn compl(i: u8) -> u8 {
|
||||
pure fn compl(i: u8) -> u8 {
|
||||
max_value ^ i
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ is either `x/y` or `x/y + 1`.
|
|||
pure fn div_floor(x: uint, y: uint) -> uint { ret x / y; }
|
||||
|
||||
#[doc = "Produce a uint suitable for use in a hash table"]
|
||||
fn hash(x: uint) -> uint { ret x; }
|
||||
pure fn hash(x: uint) -> uint { ret x; }
|
||||
|
||||
#[doc = "Iterate over the range [`lo`..`hi`)"]
|
||||
#[inline(always)]
|
||||
|
@ -188,7 +188,7 @@ fn to_str(num: uint, radix: uint) -> str {
|
|||
fn str(i: uint) -> str { ret to_str(i, 10u); }
|
||||
|
||||
#[doc = "Computes the bitwise complement"]
|
||||
fn compl(i: uint) -> uint {
|
||||
pure fn compl(i: uint) -> uint {
|
||||
max_value ^ i
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue