Skip to main content

rapier2d/dynamics/joint/multibody_joint/
multibody_joint_handle.rs

1use crate::data::Index;
2
3/// The unique handle of an multibody_joint added to a `MultibodyJointSet`.
4#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
6#[repr(transparent)]
7pub struct MultibodyJointHandle(pub Index);
8
9/// The temporary index of a multibody added to a `MultibodyJointSet`.
10#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
11#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
12#[repr(transparent)]
13pub struct MultibodyIndex(pub Index);
14
15impl MultibodyJointHandle {
16    /// Converts this handle into its (index, generation) components.
17    pub fn into_raw_parts(self) -> (u32, u32) {
18        self.0.into_raw_parts()
19    }
20
21    /// Reconstructs an handle from its (index, generation) components.
22    pub fn from_raw_parts(id: u32, generation: u32) -> Self {
23        Self(Index::from_raw_parts(id, generation))
24    }
25
26    /// An always-invalid rigid-body handle.
27    pub fn invalid() -> Self {
28        Self(Index::from_raw_parts(
29            crate::INVALID_U32,
30            crate::INVALID_U32,
31        ))
32    }
33}
34
35impl Default for MultibodyJointHandle {
36    fn default() -> Self {
37        Self::invalid()
38    }
39}