refactor: remove all explicit lifetime specifiers
This commit is contained in:
@@ -5,12 +5,12 @@ use libstardustxr::messenger::Messenger;
|
||||
use mio::net::UnixStream;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Client<'a> {
|
||||
messenger: Messenger<'a>,
|
||||
scenegraph: Scenegraph<'a>,
|
||||
pub struct Client {
|
||||
messenger: Messenger,
|
||||
scenegraph: Scenegraph,
|
||||
}
|
||||
|
||||
impl<'a> Client<'a> {
|
||||
impl Client {
|
||||
pub fn from_connection(connection: UnixStream) -> Rc<Self> {
|
||||
let client = Rc::new(Client {
|
||||
messenger: Messenger::new(connection),
|
||||
@@ -25,10 +25,10 @@ impl<'a> Client<'a> {
|
||||
self.messenger.dispatch(&self.scenegraph)
|
||||
}
|
||||
|
||||
pub fn get_messenger(&self) -> &Messenger<'a> {
|
||||
pub fn get_messenger(&self) -> &Messenger {
|
||||
&self.messenger
|
||||
}
|
||||
pub fn get_scenegraph(&self) -> &Scenegraph<'a> {
|
||||
pub fn get_scenegraph(&self) -> &Scenegraph {
|
||||
&self.scenegraph
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,38 +12,38 @@ use dashmap::DashMap;
|
||||
use rustc_hash::FxHasher;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Scenegraph<'a> {
|
||||
client: RefCell<Weak<Client<'a>>>,
|
||||
nodes: DashMap<String, RcCell<Node<'a>>, BuildHasherDefault<FxHasher>>,
|
||||
pub struct Scenegraph {
|
||||
client: RefCell<Weak<Client>>,
|
||||
nodes: DashMap<String, RcCell<Node>, BuildHasherDefault<FxHasher>>,
|
||||
}
|
||||
|
||||
impl<'a> Scenegraph<'a> {
|
||||
pub fn get_client(&self) -> Rc<Client<'a>> {
|
||||
impl Scenegraph {
|
||||
pub fn get_client(&self) -> Rc<Client> {
|
||||
self.client.borrow().upgrade().unwrap()
|
||||
}
|
||||
|
||||
pub fn set_client(&self, client: &Rc<Client<'a>>) {
|
||||
pub fn set_client(&self, client: &Rc<Client>) {
|
||||
*self.client.borrow_mut() = Rc::downgrade(client);
|
||||
}
|
||||
|
||||
pub fn add_node(&self, node: Node<'a>) -> RcCell<Node<'a>> {
|
||||
pub fn add_node(&self, node: Node) -> RcCell<Node> {
|
||||
let path = node.get_path().to_string();
|
||||
let node_rc = RcCell::new(node);
|
||||
self.nodes.insert(path, node_rc.clone());
|
||||
node_rc
|
||||
}
|
||||
|
||||
pub fn get_node(&self, path: &str) -> Option<RcCell<Node<'a>>> {
|
||||
pub fn get_node(&self, path: &str) -> Option<RcCell<Node>> {
|
||||
Some(self.nodes.get(path)?.clone())
|
||||
}
|
||||
|
||||
pub fn remove_node(&self, path: &str) -> Option<RcCell<Node<'a>>> {
|
||||
pub fn remove_node(&self, path: &str) -> Option<RcCell<Node>> {
|
||||
let (_, node) = self.nodes.remove(path)?;
|
||||
Some(node)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> scenegraph::Scenegraph for Scenegraph<'a> {
|
||||
impl scenegraph::Scenegraph for Scenegraph {
|
||||
fn send_signal(&self, path: &str, method: &str, data: &[u8]) -> Result<(), ScenegraphError> {
|
||||
self.get_node(path)
|
||||
.ok_or(ScenegraphError::NodeNotFound)?
|
||||
|
||||
@@ -16,23 +16,23 @@ use rustc_hash::FxHasher;
|
||||
pub type Signal = fn(&Node, Rc<Client>, &[u8]) -> Result<()>;
|
||||
pub type Method = fn(&Node, Rc<Client>, &[u8]) -> Result<Vec<u8>>;
|
||||
|
||||
pub struct Node<'a> {
|
||||
pub struct Node {
|
||||
uid: String,
|
||||
client: Weak<Client<'a>>,
|
||||
client: Weak<Client>,
|
||||
path: String,
|
||||
// trailing_slash_pos: usize,
|
||||
local_signals: HashMap<String, Signal, BuildHasherDefault<FxHasher>>,
|
||||
local_methods: HashMap<String, Method, BuildHasherDefault<FxHasher>>,
|
||||
destroyable: bool,
|
||||
|
||||
alias: Option<Alias<'a>>,
|
||||
alias: Option<Alias>,
|
||||
pub spatial: Option<Arc<Spatial>>,
|
||||
pub field: Option<Arc<Field>>,
|
||||
pub pulse_sender: Option<Arc<PulseSender>>,
|
||||
}
|
||||
|
||||
impl<'a> Node<'a> {
|
||||
pub fn get_client(&self) -> Option<Rc<Client<'a>>> {
|
||||
impl Node {
|
||||
pub fn get_client(&self) -> Option<Rc<Client>> {
|
||||
self.client.clone().upgrade()
|
||||
}
|
||||
// pub fn get_name(&self) -> &str {
|
||||
@@ -45,7 +45,7 @@ impl<'a> Node<'a> {
|
||||
self.destroyable
|
||||
}
|
||||
|
||||
pub fn create(client: Weak<Client<'a>>, parent: &str, name: &str, destroyable: bool) -> Self {
|
||||
pub fn create(client: Weak<Client>, parent: &str, name: &str, destroyable: bool) -> Self {
|
||||
let mut path = parent.to_string();
|
||||
path.push('/');
|
||||
path.push_str(name);
|
||||
@@ -157,16 +157,16 @@ impl<'a> Node<'a> {
|
||||
// }
|
||||
}
|
||||
|
||||
struct Alias<'a> {
|
||||
original: WeakCell<Node<'a>>,
|
||||
struct Alias {
|
||||
original: WeakCell<Node>,
|
||||
|
||||
signals: Vec<String>,
|
||||
methods: Vec<String>,
|
||||
}
|
||||
impl<'a> Alias<'a> {
|
||||
impl Alias {
|
||||
pub fn add_to(
|
||||
node: &RcCell<Node<'a>>,
|
||||
original: &RcCell<Node<'a>>,
|
||||
node: &RcCell<Node>,
|
||||
original: &RcCell<Node>,
|
||||
signals: Vec<String>,
|
||||
methods: Vec<String>,
|
||||
) {
|
||||
|
||||
@@ -12,7 +12,7 @@ use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Spatial {
|
||||
// node: WeakCell<Node<'a>>,
|
||||
// node: WeakCell<Node>,
|
||||
parent: RwLock<Option<Arc<Spatial>>>,
|
||||
transform: RwLock<Mat4>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user