I process simple strings of the format "1s: 1d", "100: 5000", etc. with this regex:
let retention_matcher = regex::Regex::new({r"^(\d+)([smhdy])?:(\d+)([smhdy])?$"}).unwrap();
I know that this regex should only match once, so I want to run regex for captures and check the number of captures.
let iter = retention_matcher.captures_iter(ts); let count = iter.count(); println!("iter.count(): {}", count); let _ : Vec<Option<(u64,u64)>> = iter.map(|regex_match| { let retval = retention_spec_to_pair(regex_match); println!("precision_opt: {:?}", retval); retval }).collect();
The problem is that the count() method is moved by iter and I can no longer use it.
src/bin/whisper.rs:147:42: 147:46 error: use of moved value: `iter` src/bin/whisper.rs:147 let _ : Vec<Option<(u64,u64)>> = iter.map(|regex_match| { ^~~~ src/bin/whisper.rs:144:21: 144:25 note: `iter` moved here because it has type `regex::re::FindCaptures<'_, '_>`, which is non-copyable src/bin/whisper.rs:144 let count = iter.count();
That doesn't make sense to me. Should the count method only return the copied usize value and not move iter ? How can I get around this problem?
source share