chore: ron 0.9 update
This commit is contained in:
parent
abda6619ff
commit
d9b15f1eb3
1 changed files with 14 additions and 2 deletions
|
|
@ -33,6 +33,7 @@ use std::{
|
||||||
cell::RefCell,
|
cell::RefCell,
|
||||||
collections::{BTreeMap, HashMap},
|
collections::{BTreeMap, HashMap},
|
||||||
fs::OpenOptions,
|
fs::OpenOptions,
|
||||||
|
io::Write,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::{atomic::AtomicBool, Arc, RwLock},
|
sync::{atomic::AtomicBool, Arc, RwLock},
|
||||||
};
|
};
|
||||||
|
|
@ -600,7 +601,15 @@ impl<'a, T: Serialize> std::ops::DerefMut for PersistenceGuard<'a, T> {
|
||||||
impl<'a, T: Serialize> Drop for PersistenceGuard<'a, T> {
|
impl<'a, T: Serialize> Drop for PersistenceGuard<'a, T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if let Some(path) = self.0.as_ref() {
|
if let Some(path) = self.0.as_ref() {
|
||||||
let writer = match OpenOptions::new()
|
let content = match ron::ser::to_string_pretty(&self.1, Default::default()) {
|
||||||
|
Ok(content) => content,
|
||||||
|
Err(err) => {
|
||||||
|
warn!("Failed to serialize: {:?}", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut writer = match OpenOptions::new()
|
||||||
.create(true)
|
.create(true)
|
||||||
.truncate(true)
|
.truncate(true)
|
||||||
.write(true)
|
.write(true)
|
||||||
|
|
@ -612,8 +621,11 @@ impl<'a, T: Serialize> Drop for PersistenceGuard<'a, T> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if let Err(err) = ron::ser::to_writer_pretty(writer, &self.1, Default::default()) {
|
|
||||||
|
if let Err(err) = writer.write_all(content.as_bytes()) {
|
||||||
warn!(?err, "Failed to persist {}", path.display());
|
warn!(?err, "Failed to persist {}", path.display());
|
||||||
|
} else {
|
||||||
|
let _ = writer.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue