rust多线程中怎么共享字符串|share String between threads

如题

fn main() {
    let mut username = String::new();
    let mut password = String::new();
    let args = std::env::args();
    if args.len()==3 {
        let mut index = 0;
        for arg in args {
            if index==1 {
                username = arg;
            }else if index==2 {
                password = arg;
            }
            index = index+1;
        }
    }
    
    
    //!!! use Arc here!!!
    let u = Arc::new(username);
    let p = Arc::new(password);

    let listen = TcpListener::bind("0.0.0.0:8088").unwrap();
    for stream in listen.incoming() {
    
    	//!!! clone Arc before move!!!
        let u1 = u.clone();
        let p1 = p.clone();
        std::thread::spawn(move || {
            //!!! cannot clone here when u moved in
            handle(stream.unwrap(), u1, p1);
        });
    }
}

0 0