feat(node): add NodeRef type

This commit is contained in:
Nova
2022-05-17 09:06:58 -04:00
parent 42c98eacc9
commit 6e3aa0a0fa
2 changed files with 7 additions and 7 deletions

View File

@@ -10,8 +10,10 @@ use std::{
use super::spatial::Spatial;
type Signal<'a> = dyn Fn(&[u8]) + 'a;
type Method<'a> = dyn Fn(&[u8]) -> Vec<u8> + 'a;
pub type Signal<'a> = dyn Fn(&[u8]) + 'a;
pub type Method<'a> = dyn Fn(&[u8]) -> Vec<u8> + 'a;
pub type NodeRef<'a> = Weak<RefCell<Node<'a>>>;
pub struct Node<'a> {
path: String,
@@ -31,7 +33,7 @@ impl<'a> Node<'a> {
self.path.as_str()
}
pub fn from_path(client: Option<&mut Client<'a>>, path: &str) -> Result<Weak<RefCell<Self>>> {
pub fn from_path(client: Option<&mut Client<'a>>, path: &str) -> Result<NodeRef<'a>> {
ensure!(path.starts_with('/'), "Invalid path {}", path);
let mut weak_messenger = Weak::default();
if client.is_some() {

View File

@@ -1,8 +1,6 @@
use super::core::Node;
use super::core::{Node, NodeRef};
use crate::core::client::Client;
use anyhow::Result;
use std::cell::RefCell;
use std::rc::Weak;
use vek::mat::repr_c::row_major::Mat4;
pub struct Spatial {
@@ -18,7 +16,7 @@ impl<'a> Spatial {
client: Option<&'a mut Client<'a>>,
path: &str,
transform: Mat4<f32>,
) -> Result<Weak<RefCell<Node<'a>>>> {
) -> Result<NodeRef<'a>> {
let node = Node::from_path(client, path)?;
node.upgrade().unwrap().borrow_mut().spatial = Some(Spatial::new(transform));
Ok(node)