CCCPaste

Borrow checker fuckery

#![feature(random)]
use std::{iter::repeat, random::random, str::Split, thread::sleep, time::Duration};

fn main() {
    let randomize = |s| random::(..).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 = vec![
        "1234&567".to_owned(),
        "45&56&78&89".to_owned(),
        "789".to_owned(),
    ];
    let mut iters: Vec> = 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));
    }
}