我正在使用rust-fuse,它将挂载选项作为&[&std::ffi::os_str::OsStr]
。看起来我应该将我收到的逗号分隔的选项字符串拆分,我是这样做的:
mod fuse {
use std::ffi::OsStr;
pub fn mount(options: &[&OsStr]) {}
}
fn example(optstr: &str) {
let mut options: &[&str] = &[];
if optstr != "" {
options = optstr.split(",").collect::<Vec<_>>().as_slice();
}
fuse::mount(options)
}
这将导致以下错误:
error[E0308]: mismatched types
--> src/main.rs:12:17
|
12 | fuse::mount(options)
| ^^^^^^^ expected struct `std::ffi::OsStr`, found str
|
= note: expected type `&[&std::ffi::OsStr]`
found type `&[&str]`
我曾经认为所有的&str
也是OsStr
,但我对Rust还很陌生,所以我猜这是不正确的。