my code:
match File::create_new(&fp) {
Ok(f) => Ok(f),
Err(x) => match x {
y if y.kind() == ErrorKind::AlreadyExists => {
File::options().read(true).append(true).open(&fp)
}
other => Err(other),
},
}
pub fn format(&self) -> io::Result<()> {
let mut data = Vec::new();
let mut fl = self.file.borrow_mut();
fl.read.rewind()?;
fl.read.read_from_file_until(&mut data, 4000)?;
let mut data = String::from_utf8_lossy(&data).into_owned();
let ind = data
.match_indices(".")
.map(|x| {
x.0
})
.collect::<Vec<usize>>();
Self::_add_char(&mut data, &ind, '\n');
println!("{} {:?}", data, ind);
dbg!(fl.write.get_mut().set_len(0))?;
dbg!(fl.write.rewind())?;
dbg!(fl.write.get_mut().write_all(data.as_bytes()))?;
Ok(())
}
error:
fl.write.get_mut().set_len(0)=Err(
Os {
code: 5,
kind: PermissionDenied,
message: "...",
},
)