refactor: modularize getting nodes and aspects

This commit is contained in:
Nova
2022-10-18 10:58:39 -04:00
parent a399db006e
commit 88555ee047
14 changed files with 91 additions and 126 deletions

View File

@@ -145,6 +145,21 @@ impl Node {
self.local_methods.insert(name.to_string(), method);
}
pub fn get_aspect<F, T>(
&self,
node_name: &'static str,
aspect_type: &'static str,
aspect_fn: F,
) -> Result<Arc<T>>
where
F: FnOnce(&Node) -> &OnceCell<Arc<T>>,
{
aspect_fn(self)
.get()
.ok_or_else(|| anyhow!("{} is not a {} node", node_name, aspect_type))
.cloned()
}
pub fn send_local_signal(
&self,
calling_client: Arc<Client>,