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, 方法的參數(shù)是, 按引用進(jìn)行傳遞的。
read_line, 把用戶的輸入, 放到一個 buf 中,緩沖, 隨著用戶的輸入改變, 比如輸入 hello, 一個字母, 一個字母地輸入, buf 也隨之改變。
注意, buf 與 cache 不同。
& 表明 userinputcontent 參數(shù)是個引用。
標(biāo)簽: