fix: remove deprecated usage of mem::uninitialized. (#1341)

This commit is contained in:
Michael Tang 2019-12-28 15:53:41 -08:00 committed by Ryan G
parent 8a3a32f286
commit 468b6b83ec

View file

@ -3,7 +3,7 @@ use stdweb::web::{window, IWindowOrWorker, TimeoutHandle};
#[derive(Debug)] #[derive(Debug)]
pub struct Timeout { pub struct Timeout {
handle: TimeoutHandle, handle: Option<TimeoutHandle>,
} }
impl Timeout { impl Timeout {
@ -12,14 +12,14 @@ impl Timeout {
F: 'static + FnMut(), F: 'static + FnMut(),
{ {
Timeout { Timeout {
handle: window().set_clearable_timeout(f, duration.as_millis() as u32), handle: Some(window().set_clearable_timeout(f, duration.as_millis() as u32)),
} }
} }
} }
impl Drop for Timeout { impl Drop for Timeout {
fn drop(&mut self) { fn drop(&mut self) {
let handle = std::mem::replace(&mut self.handle, unsafe { std::mem::uninitialized() }); let handle = self.handle.take().unwrap();
handle.clear(); handle.clear();
} }
} }