我有以下代码:
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub struct Trip<'a> {
pub cod: &'a str,
}
#[derive(Debug, Clone, Copy)]
pub struct ami<'a> {
pub tlc: &'a str,
}
impl<'a> Trip<'a> {
fn new(road: &'a str) -> Trip {
assert_eq!(
3,
road.trim().len(),
"Triplet doesn't have three Nucleotides"
);
let trip = road[0..].iter().flat_map(|s| s.chars()).collect();
Triplet { cod: trip }
}
}
我遇到以下错误:
error[E0599]: no method named `iter` found for type `str` in the current scope
--> src/gcode/gcode.rs:20:30
|
20 | let trip = [0..].iter()
| ^^^^
据我所知,new
关联函数接收以生命周期为基准的str
作为输入参数,并输出带有Trip
字段的cod
结构。在此过程中,输入由迭代器使用。
我应该收到有关生命周期无效的错误,但是在当前范围内,我没有办法使用str
吗?
这是为什么?