robot_description_builder/link/
link_parent.rs1use std::sync::Weak;
2
3use crate::{
4 cluster_objects::kinematic_data_tree::KinematicDataTree, joint::Joint, utils::WeakLock,
5};
6
7#[derive(Debug)]
9pub enum LinkParent {
10 Joint(WeakLock<Joint>),
12 KinematicTree(Weak<KinematicDataTree>),
15}
16
17impl LinkParent {
18 pub fn is_valid_reference(&self) -> bool {
21 match self {
22 LinkParent::Joint(joint) => joint.upgrade().is_some(),
23 LinkParent::KinematicTree(tree) => tree.upgrade().is_some(),
24 }
25 }
26}
27
28impl Clone for LinkParent {
29 fn clone(&self) -> Self {
30 match self {
31 Self::Joint(joint) => Self::Joint(Weak::clone(joint)),
32 Self::KinematicTree(tree) => Self::KinematicTree(Weak::clone(tree)),
33 }
34 }
35}
36
37impl From<Weak<KinematicDataTree>> for LinkParent {
38 fn from(value: Weak<KinematicDataTree>) -> Self {
39 Self::KinematicTree(value)
40 }
41}
42
43impl PartialEq for LinkParent {
44 fn eq(&self, other: &Self) -> bool {
45 match (self, other) {
46 (Self::Joint(l0), Self::Joint(r0)) => l0.ptr_eq(r0),
47 (Self::KinematicTree(l0), Self::KinematicTree(r0)) => l0.ptr_eq(r0),
48 _ => false,
49 }
50 }
51}