Don't panic in Drop.

The same behavior exists (without logging) in BufWriter from std crate.
It's not recommended to depend on flush during drop.
Instead user should flush explicitly and check for error.
This commit is contained in:
Rafał Harabień 2017-11-07 01:13:02 +01:00
parent 4613196733
commit de9977e571
2 changed files with 8 additions and 2 deletions

View File

@ -138,7 +138,10 @@ impl <'a, 'b> File<'a, 'b> {
impl<'a, 'b> Drop for File<'a, 'b> {
fn drop(&mut self) {
self.flush().expect("flush failed");
match self.flush() {
Err(err) => error!("flush failed {}", err),
_ => {},
}
}
}

View File

@ -130,6 +130,9 @@ impl<T: Read+Write+Seek> Seek for BufStream<T> {
impl<T: Read+Write+Seek> Drop for BufStream<T> {
fn drop(&mut self) {
self.flush().expect("flush failed!");
match self.flush() {
Err(err) => error!("flush failed {}", err),
_ => {},
}
}
}