aboutsummaryrefslogtreecommitdiff
path: root/crates/whirl_server/src/interaction/shared.rs
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-20 17:05:59 -0700
committerFuwn <[email protected]>2021-05-20 17:05:59 -0700
commit9e2121baf98b6fdc15cde6c387a7845a0b3f95d6 (patch)
tree15460f59799a9f655ac5b213e4b8a8903d1e57e4 /crates/whirl_server/src/interaction/shared.rs
parentfeat(readme): add sqlfluff as a dev dep (diff)
downloadwhirl-9e2121baf98b6fdc15cde6c387a7845a0b3f95d6.tar.xz
whirl-9e2121baf98b6fdc15cde6c387a7845a0b3f95d6.zip
refactor(global): move crates around, stricter module isolation
Diffstat (limited to 'crates/whirl_server/src/interaction/shared.rs')
-rw-r--r--crates/whirl_server/src/interaction/shared.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/crates/whirl_server/src/interaction/shared.rs b/crates/whirl_server/src/interaction/shared.rs
new file mode 100644
index 0000000..c2ee671
--- /dev/null
+++ b/crates/whirl_server/src/interaction/shared.rs
@@ -0,0 +1,28 @@
+// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
+// SPDX-License-Identifier: GPL-3.0-only
+
+use std::collections::HashMap;
+
+use bytes::BytesMut;
+
+use crate::types::Tx;
+
+pub struct Shared {
+ pub peers: HashMap<String, Tx>,
+}
+impl Shared {
+ pub fn new() -> Self {
+ Shared {
+ peers: HashMap::new(),
+ }
+ }
+
+ pub async fn broadcast(&mut self, message: &[u8]) {
+ for peer in self.peers.iter_mut() {
+ peer.1.send(BytesMut::from(message)).unwrap();
+ }
+ }
+}
+impl Default for Shared {
+ fn default() -> Self { Self::new() }
+}