Make Runnable::handler take self by value.

With my thanks to kimundi and eddyb for their help in making this approach
work.
This commit is contained in:
Ms2ger 2015-01-10 16:39:00 +01:00
parent 14ff55443f
commit b2f40b9873
3 changed files with 8 additions and 6 deletions

View file

@ -115,7 +115,8 @@ impl WorkerMessageHandler {
} }
impl Runnable for WorkerMessageHandler { impl Runnable for WorkerMessageHandler {
fn handler(&self){ fn handler(self: Box<WorkerMessageHandler>) {
Worker::handle_message(self.addr.clone(), self.data); let this = *self;
Worker::handle_message(this.addr, this.data);
} }
} }

View file

@ -85,8 +85,9 @@ impl XHRProgressHandler {
} }
impl Runnable for XHRProgressHandler { impl Runnable for XHRProgressHandler {
fn handler(&self) { fn handler(self: Box<XHRProgressHandler>) {
XMLHttpRequest::handle_progress(self.addr.clone(), self.progress.clone()); let this = *self;
XMLHttpRequest::handle_progress(this.addr, this.progress);
} }
} }

View file

@ -96,7 +96,7 @@ pub enum TimerSource {
} }
pub trait Runnable { pub trait Runnable {
fn handler(&self); fn handler(self: Box<Self>);
} }
/// Messages used to control script event loops, such as ScriptTask and /// Messages used to control script event loops, such as ScriptTask and
@ -1385,7 +1385,7 @@ impl DocumentProgressHandler {
} }
impl Runnable for DocumentProgressHandler { impl Runnable for DocumentProgressHandler {
fn handler(&self) { fn handler(self: Box<DocumentProgressHandler>) {
match self.task { match self.task {
DocumentProgressTask::DOMContentLoaded => { DocumentProgressTask::DOMContentLoaded => {
self.dispatch_dom_content_loaded(); self.dispatch_dom_content_loaded();