我正在寻找最好的方法String
来Windows<T>
使用windows
为切片提供的功能.
我理解如何以这种方式使用Windows:
fn main() {
let tst = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
let mut windows = tst.windows(3);
// prints ['a', 'b', 'c']
println!("{:?}", windows.next().unwrap());
// prints ['b', 'c', 'd']
println!("{:?}", windows.next().unwrap());
// etc...
}
Run Code Online (Sandbox Code Playgroud)
但是在处理这个问题时我有点迷失:
fn main() {
let tst = String::from("abcdefg");
let inter = ? //somehow create slice of character from tst
let mut windows = inter.windows(3);
// prints ['a', 'b', 'c']
println!("{:?}", windows.next().unwrap());
// prints ['b', …
Run Code Online (Sandbox Code Playgroud)