相关疑难解决方法(0)

Rust中的.. =(点点等于)运算符是什么?

..=在一些Rust代码中看到了这个运算符:

for s in 2..=9 {
    // some code here
}
Run Code Online (Sandbox Code Playgroud)

它是什么?

syntax operators rust

20
推荐指数
1
解决办法
703
查看次数

如何在范围中包含最终值?

我想创建一个带有'a'..'z'值(包括)的向量.

这不编译:

let vec: Vec<char> = ('a'..'z'+1).collect();
Run Code Online (Sandbox Code Playgroud)

什么是惯用的方式'a'..'z'

rust

9
推荐指数
2
解决办法
2700
查看次数

为什么不能在表达式中使用...语法?

我正在尝试理解...语法.考虑以下程序:

fn how_many(x: i32) -> &'static str {
    match x {
        0 => "no oranges",
        1 => "an orange",
        2 | 3 => "two or three oranges",
        9...11 => "approximately 10 oranges",
        _ => "few oranges",
    }
}

fn pattern_matching() {
    for x in 0..13 {
        println!("{} : I have {} ", x, how_many(x));
    }
}

fn main() {
    // println!("{:?}", (2...6));
    pattern_matching();
}
Run Code Online (Sandbox Code Playgroud)

在上面的程序中,9...11模式匹配中使用的编译很好.当我尝试使用相同的内容时,println!("{:?}", (2...6));我得到编译错误:

error: `...` syntax cannot be used in expressions …
Run Code Online (Sandbox Code Playgroud)

rust

2
推荐指数
1
解决办法
385
查看次数

标签 统计

rust ×3

operators ×1

syntax ×1