Skip to content

Commit

Permalink
Implemented Debug on all structs
Browse files Browse the repository at this point in the history
  • Loading branch information
r3v2d0g committed Oct 20, 2019
1 parent 2d5e537 commit 329e79e
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 5 deletions.
4 changes: 4 additions & 0 deletions bastion/src/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::task::{Context, Poll};
pub(super) type Sender = UnboundedSender<BastionMessage>;
pub(super) type Receiver = UnboundedReceiver<BastionMessage>;

#[derive(Debug)]
pub(super) struct Broadcast {
id: BastionId,
sender: Sender,
Expand All @@ -19,13 +20,15 @@ pub(super) struct Broadcast {
children: FxHashMap<BastionId, Sender>,
}

#[derive(Debug)]
pub(super) enum Parent {
None,
System,
Supervisor(SupervisorRef),
Children(ChildrenRef),
}

#[derive(Debug)]
pub(super) enum BastionMessage {
Start,
Stop,
Expand All @@ -38,6 +41,7 @@ pub(super) enum BastionMessage {
Faulted { id: BastionId },
}

#[derive(Debug)]
pub(super) enum Deployment {
Supervisor(Supervisor),
Children(Children),
Expand Down
28 changes: 26 additions & 2 deletions bastion/src/children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use futures::stream::FuturesUnordered;
use fxhash::FxHashMap;
use qutex::Qutex;
use std::any::Any;
use std::fmt::Debug;
use std::fmt::{self, Debug, Formatter};
use std::future::Future;
use std::iter::FromIterator;
use std::panic::AssertUnwindSafe;
Expand Down Expand Up @@ -61,7 +61,7 @@ pub(super) struct Children {
started: bool,
}

#[derive(Clone)]
#[derive(Debug)]
pub struct ChildrenRef {
id: BastionId,
sender: Sender,
Expand Down Expand Up @@ -402,3 +402,27 @@ impl Child {
}
}
}

impl Debug for Children {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
fmt.debug_struct("Children")
.field("bcast", &self.bcast)
.field("supervisor", &self.supervisor)
.field("launched", &self.launched)
.field("redundancy", &self.redundancy)
.field("pre_start_msgs", &self.pre_start_msgs)
.field("started", &self.started)
.finish()
}
}

impl Debug for Child {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
fmt.debug_struct("Child")
.field("bcast", &self.bcast)
.field("state", &self.state)
.field("pre_start_msgs", &self.pre_start_msgs)
.field("started", &self.started)
.finish()
}
}
2 changes: 2 additions & 0 deletions bastion/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ pub(super) const NIL_ID: BastionId = BastionId(Uuid::nil());
#[derive(Hash, Eq, PartialEq, Debug, Clone)]
pub struct BastionId(Uuid);

#[derive(Debug)]
pub struct BastionContext {
id: BastionId,
children: ChildrenRef,
supervisor: SupervisorRef,
state: Qutex<ContextState>,
}

#[derive(Debug)]
pub(super) struct ContextState {
msgs: VecDeque<Box<dyn Message>>,
}
Expand Down
1 change: 1 addition & 0 deletions bastion/src/proc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};

#[derive(Debug)]
pub(super) struct Proc<T> {
recver: Receiver<T>,
}
Expand Down
4 changes: 3 additions & 1 deletion bastion/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ use crate::context::BastionId;
use crate::supervisor::{Supervisor, SupervisorRef};
use dashmap::DashMap;

#[derive(Debug)]
pub(super) struct Registry {
registered: DashMap<BastionId, Registrant>,
}

#[derive(Debug)]
struct Registrant {
sender: Sender,
ty: RegistrantType,
}

#[derive(Eq, PartialEq)]
#[derive(Eq, PartialEq, Debug)]
enum RegistrantType {
Supervisor,
Children,
Expand Down
6 changes: 4 additions & 2 deletions bastion/src/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use fxhash::FxHashMap;
use std::ops::RangeFrom;
use std::task::Poll;

#[derive(Debug)]
pub struct Supervisor {
bcast: Broadcast,
order: Vec<BastionId>,
Expand All @@ -20,19 +21,20 @@ pub struct Supervisor {
started: bool,
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct SupervisorRef {
id: BastionId,
sender: Sender,
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum SupervisionStrategy {
OneForOne,
OneForAll,
RestForOne,
}

#[derive(Debug)]
enum Supervised {
Supervisor(Supervisor),
Children(Children),
Expand Down
1 change: 1 addition & 0 deletions bastion/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ lazy_static! {
pub(super) static ref RUNTIME: Runtime = Builder::new().panic_handler(|_| ()).build().unwrap();
}

#[derive(Debug)]
pub(super) struct System {
bcast: Broadcast,
launched: FxHashMap<BastionId, Proc<Supervisor>>,
Expand Down

0 comments on commit 329e79e

Please sign in to comment.