Skip to content

Commit e26f992

Browse files
committed
auto merge of #6036 : huonw/rust/core-less-at, r=nikomatsakis
From a cursory `git grep` this removes the last part of `core` that requires on `@` (other than `io` and the task local data section). It renames `RandRes` to ~~StdRng~~ `IsaacRng` and `XorShiftState` to `XorShiftRng` as well as moving their constructors to static methods. To go with this, it adds `rng()` which is designed to be used when the programmer just wants a random number generator, without caring about which exact algorithm is being used. It also removes all the `gen_int`, `gen_uint`, `gen_char` (etc) methods on `RngUtil` (by moving the defintions to the actual `Rand` instances). The replacement is using `RngUtil::gen`, either type-inferred or with an annotation (`rng.gen::<uint>()`). I tried to have the `Rng` and `RngUtil` traits exported by `core::prelude` (since `core::rand` (except for `random()`) is useless without them), but this caused [an explosion of (seemingly unrelated) `error: unresolved import`'s](https://gist.github.com/5451839).
2 parents c8ac057 + 9860fe1 commit e26f992

20 files changed

+397
-538
lines changed

src/libcore/flate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn inflate_bytes(bytes: &const [u8]) -> ~[u8] {
8585
#[test]
8686
#[allow(non_implicitly_copyable_typarams)]
8787
fn test_flate_round_trip() {
88-
let r = rand::Rng();
88+
let r = rand::rng();
8989
let mut words = ~[];
9090
for 20.times {
9191
words.push(r.gen_bytes(r.gen_uint_range(1, 10)));

src/libcore/hashmap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn resize_at(capacity: uint) -> uint {
5656
pub fn linear_map_with_capacity<K:Eq + Hash,V>(
5757
initial_capacity: uint) -> HashMap<K, V> {
5858
let r = rand::task_rng();
59-
linear_map_with_capacity_and_keys(r.gen_u64(), r.gen_u64(),
59+
linear_map_with_capacity_and_keys(r.gen(), r.gen(),
6060
initial_capacity)
6161
}
6262

src/libcore/os.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ mod tests {
12591259
}
12601260
12611261
fn make_rand_name() -> ~str {
1262-
let rng: @rand::Rng = rand::Rng();
1262+
let rng = rand::rng();
12631263
let n = ~"TEST" + rng.gen_str(10u);
12641264
assert!(getenv(n).is_none());
12651265
n

0 commit comments

Comments
 (0)