Skip to main content

rapier2d/geometry/
collider_handle.rs

1/// The unique identifier of a collider added to a collider set.
2#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Default)]
3#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
4#[repr(transparent)]
5pub struct ColliderHandle(pub crate::data::arena::Index);
6
7impl ColliderHandle {
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 collider 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}