Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for sending messages to another child and hide Uuids in…
…side a BastionID struct
- Loading branch information
Showing
3 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,30 @@ | ||
use crate::broadcast::Sender; | ||
use crate::bastion::REGISTRY; | ||
use crate::broadcast::{BastionMessage, Sender}; | ||
use crate::children::Message; | ||
use uuid::Uuid; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct BastionID(Uuid); | ||
|
||
pub struct BastionContext { | ||
id: Uuid, | ||
id: BastionID, | ||
parent: Sender, | ||
} | ||
|
||
impl BastionContext { | ||
pub(super) fn new(id: Uuid, parent: Sender) -> Self { | ||
let id = BastionID(id); | ||
|
||
BastionContext { id, parent } | ||
} | ||
|
||
pub fn id(&self) -> &Uuid { | ||
pub fn id(&self) -> &BastionID { | ||
&self.id | ||
} | ||
|
||
pub fn send_msg(&self, id: &BastionID, msg: Box<dyn Message>) -> Result<(), Box<dyn Message>> { | ||
let msg = BastionMessage::msg(msg); | ||
|
||
REGISTRY.send_child(&id.0, msg).map_err(|msg| msg.into_msg().unwrap()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters