Skip to main content

rapier2d/dynamics/
rigid_body_handle.rs

1/// The unique handle of a rigid body added to a `RigidBodySet`.
2#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Default)]
3#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
4#[repr(transparent)]
5pub struct RigidBodyHandle(pub crate::data::arena::Index);
6
7impl RigidBodyHandle {
8    /// Converts this handle into its (index, generation) components.
9    pub fn into_raw_parts(self) -> (u32, u32) {
10        self.0.into_raw_parts()
11    }
12
13    /// Reconstructs an handle from its (index, generation) components.
14    pub fn from_raw_parts(id: u32, generation: u32) -> Self {
15        Self(crate::data::arena::Index::from_raw_parts(id, generation))
16    }
17
18    /// An always-invalid rigid-body handle.
19    pub fn invalid() -> Self {
20        Self(crate::data::arena::Index::from_raw_parts(
21            crate::INVALID_U32,
22            crate::INVALID_U32,
23        ))
24    }
25}