小编Cas*_*ell的帖子

如何初始化一个数组,以便 Rust 知道它是一个“String”数组,而不是“str”数组?

我对 Rust 比较陌生,正在尝试执行以下操作:

pub fn route(request: &[String]) {
    let commands = ["one thing", "another thing", "something else"];

    for command in commands.iter() {
        if command == request {
            // do something
        } else {
            // throw error
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试构建它时,出现编译器错误:

pub fn route(request: &[String]) {
    let commands = ["one thing", "another thing", "something else"];

    for command in commands.iter() {
        if command == request {
            // do something
        } else {
            // throw error
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

rust

3
推荐指数
1
解决办法
2115
查看次数

标签 统计

rust ×1