Mountain/RPC/EchoAction/
ExtensionHostRegistry.rs1#![allow(non_snake_case)]
2
3use std::{collections::HashMap, sync::Arc};
8
9use tokio::sync::RwLock;
10
11pub struct Struct {
12 Hosts:Arc<RwLock<HashMap<String, String>>>,
13}
14
15impl Struct {
16 pub fn new() -> Self { Self { Hosts:Arc::new(RwLock::new(HashMap::new())) } }
17
18 pub async fn Record(&self, ExtensionIdentifier:String, HostIdentifier:String) {
19 self.Hosts.write().await.insert(ExtensionIdentifier, HostIdentifier);
20 }
21
22 pub async fn Forget(&self, ExtensionIdentifier:&str) { self.Hosts.write().await.remove(ExtensionIdentifier); }
23
24 pub async fn Resolve(&self, ExtensionIdentifier:&str) -> Option<String> {
25 self.Hosts.read().await.get(ExtensionIdentifier).cloned()
26 }
27
28 pub async fn Count(&self) -> usize { self.Hosts.read().await.len() }
29}
30
31impl Default for Struct {
32 fn default() -> Self { Self::new() }
33}