我无法弄清楚如何使用类型为~str的密钥的HashMap。例如, let mut map: hashmap::HashMap<~str, int> = hashmap::HashMap::new();
// Inserting is fine, I just have to copy the string.
map.insert("hello".to_str(), 1);
// If I
我正在构建Rust教程的示例。当我尝试编译此示例时: use std::float;
use std::num::atan;
fn angle(vector: (float, float)) -> float {
let pi = float::consts::pi;
match vector {
(0f, y) if y < 0f => 1.5 * pi,
的代码: enum A {
Foo,
Bar,
Baz(~str)
}
#[test]
fn test_vector(){
let test_vec = ~[Foo, Bar, Baz(~"asdf")];
for x in test_vec.iter() {
match x {
&Foo => true,
我正在写一个箱子,它包含分布在多个文件中的多个模块。这些模块是相互依赖的,即一些模块使用该箱子内的其他模块。 是否有可能在这些模块中运行测试与箱子中的其他模块分开?如果some_module.rs包含对此包中其他模块的引用,则运行rust test some_module.rs不起作用。运行rust test my_crate.rc确实有效,但它运行来自所有箱子模块的测试,这不是我想要的。
我有大致有以下代码: let val = util::replace(&mut self.some_field[i], self.some_method());
它失败,出现以下消息: unrelated.rs:61:65: 61:70 error: cannot borrow `*self` as immutable because it is also borrowed as mutabl