From f9ee8fb6e2290909536588105f740e4926abd1ea Mon Sep 17 00:00:00 2001 From: Matthieu Le brazidec Date: Tue, 12 Nov 2019 20:00:47 +0100 Subject: [PATCH] Fixed formatting and errors. --- bastion/src/children.rs | 100 +++++++++++++++++++++++++++++----------- bastion/src/lib.rs | 3 +- bastion/src/system.rs | 7 ++- 3 files changed, 81 insertions(+), 29 deletions(-) diff --git a/bastion/src/children.rs b/bastion/src/children.rs index c7b7082e..ecbe3bab 100644 --- a/bastion/src/children.rs +++ b/bastion/src/children.rs @@ -310,7 +310,11 @@ impl Children { /// /// [`with_exec`]: #method.with_exec pub fn with_redundancy(mut self, redundancy: usize) -> Self { - trace!("Children({}): Setting redundancy: {:?}", self.id(), redundancy); + trace!( + "Children({}): Setting redundancy: {:?}", + self.id(), + redundancy + ); self.redundancy = redundancy; self } @@ -359,7 +363,11 @@ impl Children { /// /// [`Callbacks`]: struct.Callbacks.html pub fn with_callbacks(mut self, callbacks: Callbacks) -> Self { - trace!("Children({}): Setting callbacks: {:?}", self.id(), callbacks); + trace!( + "Children({}): Setting callbacks: {:?}", + self.id(), + callbacks + ); self.callbacks = callbacks; self } @@ -418,7 +426,11 @@ impl Children { // FIXME BastionMessage::SuperviseWith(_) => unimplemented!(), BastionMessage::Message(ref message) => { - debug!("Children({}): Broadcasting a message: {:?}", self.id(), message); + debug!( + "Children({}): Broadcasting a message: {:?}", + self.id(), + message + ); self.bcast.send_children(msg); } BastionMessage::Stopped { id } => { @@ -456,7 +468,11 @@ impl Children { match poll!(&mut self.bcast.next()) { // TODO: Err if started == true? Poll::Ready(Some(BastionMessage::Start)) => { - trace!("Children({}): Received a new message (started=false): {:?}", self.id(), BastionMessage::Start); + trace!( + "Children({}): Received a new message (started=false): {:?}", + self.id(), + BastionMessage::Start + ); debug!("Children({}): Starting.", self.id()); self.started = true; @@ -466,7 +482,10 @@ impl Children { let msgs = self.pre_start_msgs.drain(..).collect::>(); self.pre_start_msgs.shrink_to_fit(); - debug!("Children({}): Replaying messages received before starting.", self.id()); + debug!( + "Children({}): Replaying messages received before starting.", + self.id() + ); for msg in msgs { trace!("Children({}): Replaying message: {:?}", self.id(), msg); if self.handle(msg).await.is_err() { @@ -475,11 +494,19 @@ impl Children { } } Poll::Ready(Some(msg)) if !self.started => { - trace!("Children({}): Received a new message (started=false): {:?}", self.id(), msg); + trace!( + "Children({}): Received a new message (started=false): {:?}", + self.id(), + msg + ); self.pre_start_msgs.push(msg); } Poll::Ready(Some(msg)) => { - trace!("Children({}): Received a new message (started=true): {:?}", self.id(), msg); + trace!( + "Children({}): Received a new message (started=true): {:?}", + self.id(), + msg + ); if self.handle(msg).await.is_err() { return self; } @@ -509,13 +536,16 @@ impl Children { let state = ContextState::new(); let state = Qutex::new(state); - let ctx = - BastionContext::new(id, child_ref, children, supervisor, state.clone()); + let ctx = BastionContext::new(id, child_ref, children, supervisor, state.clone()); let exec = (self.init.0)(ctx); self.bcast.register(&bcast); - debug!("Children({}): Initializing Child({}).", self.id(), bcast.id()); + debug!( + "Children({}): Initializing Child({}).", + self.id(), + bcast.id() + ); let child = Child::new(exec, bcast, state); debug!("Children({}): Launching Child({}).", self.id(), child.id()); let id = child.id().clone(); @@ -679,7 +709,7 @@ impl ChildrenRef { /// # } /// ``` pub fn stop(&self) -> Result<(), ()> { - debug!("ChildrenRef({}): Stopping."); + debug!("ChildrenRef({}): Stopping.", self.id); let msg = BastionMessage::stop(); self.send(msg).map_err(|_| ()) } @@ -708,7 +738,7 @@ impl ChildrenRef { /// # } /// ``` pub fn kill(&self) -> Result<(), ()> { - debug!("ChildrenRef({}): Killing."); + debug!("ChildrenRef({}): Killing.", self.id); let msg = BastionMessage::kill(); self.send(msg).map_err(|_| ()) } @@ -746,7 +776,7 @@ impl Child { ProcStack::default().with_after_panic(move || { // FIXME: clones let id = id.clone(); - warn!("Child({}): Panicked."); + warn!("Child({}): Panicked.", id); let msg = BastionMessage::faulted(id); // TODO: handle errors @@ -788,7 +818,7 @@ impl Child { // FIXME BastionMessage::SuperviseWith(_) => unimplemented!(), BastionMessage::Message(msg) => { - debug!("Child({}): Received a message: {:?}", msg); + debug!("Child({}): Received a message: {:?}", self.id(), msg); let mut state = self.state.clone().lock_async().await.map_err(|_| ())?; state.push_msg(msg); } @@ -807,14 +837,21 @@ impl Child { match poll!(&mut self.bcast.next()) { // TODO: Err if started == true? Poll::Ready(Some(BastionMessage::Start)) => { - trace!("Child({}): Received a new message (started=false): {:?}", self.id(), BastionMessage::Start); + trace!( + "Child({}): Received a new message (started=false): {:?}", + self.id(), + BastionMessage::Start + ); debug!("Child({}): Starting.", self.id()); self.started = true; let msgs = self.pre_start_msgs.drain(..).collect::>(); self.pre_start_msgs.shrink_to_fit(); - debug!("Child({}): Replaying messages received before starting.", self.id()); + debug!( + "Child({}): Replaying messages received before starting.", + self.id() + ); for msg in msgs { trace!("Child({}): Replaying message: {:?}", self.id(), msg); if self.handle(msg).await.is_err() { @@ -825,13 +862,21 @@ impl Child { continue; } Poll::Ready(Some(msg)) if !self.started => { - trace!("Child({}): Received a new message (started=false): {:?}", self.id(), msg); + trace!( + "Child({}): Received a new message (started=false): {:?}", + self.id(), + msg + ); self.pre_start_msgs.push(msg); continue; } Poll::Ready(Some(msg)) => { - trace!("Child({}): Received a new message (started=true): {:?}", self.id(), msg); + trace!( + "Child({}): Received a new message (started=true): {:?}", + self.id(), + msg + ); if self.handle(msg).await.is_err() { return; } @@ -853,13 +898,16 @@ impl Child { match poll!(&mut self.exec) { Poll::Ready(Ok(())) => { - debug!("Child({}): The future finished executing successfully.") - return self.stopped() - }, + debug!( + "Child({}): The future finished executing successfully.", + self.id() + ); + return self.stopped(); + } Poll::Ready(Err(())) => { - warn!("Child({}): The future returned an error."); - return self.faulted() - }, + warn!("Child({}): The future returned an error.", self.id()); + return self.faulted(); + } Poll::Pending => (), } @@ -1076,7 +1124,7 @@ impl ChildRef { /// # } /// ``` pub fn stop(&self) -> Result<(), ()> { - debug!("ChildRef({}): Stopping."); + debug!("ChildRef({}): Stopping.", self.id); let msg = BastionMessage::stop(); self.send(msg).map_err(|_| ()) } @@ -1105,7 +1153,7 @@ impl ChildRef { /// # } /// ``` pub fn kill(&self) -> Result<(), ()> { - debug!("ChildRef({}): Killing."); + debug!("ChildRef({}): Killing.", self.id); let msg = BastionMessage::kill(); self.send(msg).map_err(|_| ()) } diff --git a/bastion/src/lib.rs b/bastion/src/lib.rs index fe545587..f8f96f1b 100644 --- a/bastion/src/lib.rs +++ b/bastion/src/lib.rs @@ -51,7 +51,8 @@ #![warn(missing_docs)] #![warn(missing_debug_implementations)] -#[macro_use] extern crate log; +#[macro_use] +extern crate log; pub use self::bastion::Bastion; pub use self::callbacks::Callbacks; diff --git a/bastion/src/system.rs b/bastion/src/system.rs index dfe2f503..c7768cb7 100644 --- a/bastion/src/system.rs +++ b/bastion/src/system.rs @@ -125,7 +125,7 @@ impl System { } Poll::Ready(Some(None)) => { error!("System: Unknown supervisor cancelled instead of stopped."); - }, + } Poll::Ready(None) => return supervisors, Poll::Pending => pending!(), } @@ -255,7 +255,10 @@ impl System { match poll!(&mut self.bcast.next()) { // TODO: Err if started == true? Poll::Ready(Some(BastionMessage::Start)) => { - trace!("System: Received a new message (started=false): {:?}", BastionMessage::Start); + trace!( + "System: Received a new message (started=false): {:?}", + BastionMessage::Start + ); info!("System: Starting."); self.started = true;