rust 读取命令行输入
2022-11-17 10:36 作者:skylon2001 | 我要投稿
io::stdin::read_line(&mut userinputcontent).expect("err got, when read user input content")
mut means userinputcontent can be modify, & means referrer, can be use in other place....

其实 userinputcontent 就是变量名字, 是一个 buf
By default, &somevar cannot be modify, in order to modify, use &mut somevar.
read_line, 方法的参数是, 按引用进行传递的。
read_line, 把用户的输入, 放到一个 buf 中,缓冲, 随着用户的输入改变, 比如输入 hello, 一个字母, 一个字母地输入, buf 也随之改变。
注意, buf 与 cache 不同。
& 表明 userinputcontent 参数是个引用。