可以在函数中添加一行代码,使用print!宏来输出提示信息,例如:

async fn get_user_input() -> String {
    print!("Please enter your input: ");
    let mut input_buf = String::new();
    let _input = io::stdin().read_line(&mut input_buf).expect("fail to get user input.");
    input_buf
}

这样在调用该函数时,会先打印出"Please enter your input: ",然后等待用户输入。

async fn get_user_input() -> String {
 let mut input_buf = String::new();
 let _input = io::stdin().read_line(&mut input_buf).expect(

原文地址: https://www.cveoy.top/t/topic/g8q 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录