Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(random)]
- use std::{iter::repeat, random::random, str::Split, thread::sleep, time::Duration};
- fn main() {
- let randomize = |s| random::<bool>(..).then_some(s);
- let mut sources = vec![
- repeat("1234&567".to_owned()).filter_map(randomize),
- repeat("45&56&78&89".to_owned()).filter_map(randomize),
- repeat("789".to_owned()).filter_map(randomize),
- ];
- let mut texts: Vec<String> = vec![
- "1234&567".to_owned(),
- "45&56&78&89".to_owned(),
- "789".to_owned(),
- ];
- let mut iters: Vec<Split<_>> = texts.iter().map(|s| s.split('&')).collect();
- loop {
- for iter in iters.iter_mut() {
- if let Some(s) = iter.next() {
- print!("{}", s);
- }
- }
- println!("");
- let new_strings: Vec<(usize, String)> = sources
- .iter_mut()
- .enumerate()
- .filter_map(|(i, s)| s.next().map(|s| (i, s)))
- .collect();
- for (i, s) in new_strings {
- drop(iters);
- texts[i] = s;
- // Want to rebuild one iterator for a new string
- // iters[i] = s.split('&');
- iters = texts.iter().map(|s| s.split('&')).collect();
- }
- sleep(Duration::from_millis(100));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment