use rand::prelude;
use std::fs;
fn replace(path : String) {
for i in read_to_string(path).split_witespace().collect::<Vec<&str>>() {
if i == "" {
continue;
}
path = path.replace(i,random::<i16>();)
}
}
fn main() {
replace("xxx.txt".into());
}
but,when I cat xxx.txt.I see that the numbers were same.
How to generate different?
Please use rustfmt to fix your code formatting. Inconsistent indentation makes the code hard to read.
If I were to fix the syntax, mutability, type, and borrowing errors which prove you never tested this code, this
still wouldn't do anything like editing xxx.txt. How could it? You only read_to_string once and never write to the file at all. Moreover, path is a variable that contains the file name, not its contents.