我想要获取一个随机数,但是我不希望它以uint而不是int的形式返回...我不确定这个匹配是否正确,但编译器无法进行这个from_uint操作,因为它从未听说过:
fn get_random(max: &int) -> int {
// Here we use * to dereference max
// ...that is, we access the value at
// the pointer location rather than
// trying to do math using the actual
// pointer itself
match int::from_uint(rand::random::<uint>() % *max + 1) {
Some(n) => n,
None => 0,
}
}
from_uint
从std::num
中移除。 - KindDragon