robot_description_builder/link/
link_parent.rs

1use std::sync::Weak;
2
3use crate::{
4	cluster_objects::kinematic_data_tree::KinematicDataTree, joint::Joint, utils::WeakLock,
5};
6
7/// A element to contain a reference to the parent element of a `Link`.
8#[derive(Debug)]
9pub enum LinkParent {
10	/// Variant for when the Parent of a [`Link`](super::Link) is [`Joint`].
11	Joint(WeakLock<Joint>),
12	/// Variant for when this [`Link`](super::Link) element is the root of the [kinematic tree](crate::KinematicTree).
13	// TODO: Change link of kinematictree to a submodule
14	KinematicTree(Weak<KinematicDataTree>),
15}
16
17impl LinkParent {
18	/// Validate if the reference to the parent is still valid.
19	// TODO: Example?
20	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}