|
|
|
@ -78,9 +78,13 @@ impl Relation { |
|
|
|
|
#[inline] |
|
|
|
|
#[must_use] |
|
|
|
|
pub fn from_bits(bits: u64) -> Option<Self> { |
|
|
|
|
let kind = (bits >> 32) as u32; |
|
|
|
|
let target = bits as u32; |
|
|
|
|
let high = (bits >> 32) as u32; |
|
|
|
|
if let (kind, Flags::RELATION) = Flags::unpack(high)? { |
|
|
|
|
Self::new_checked(kind, target) |
|
|
|
|
} else { |
|
|
|
|
None |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[inline] |
|
|
|
@ -94,7 +98,12 @@ impl TryFrom<Component> for Relation { |
|
|
|
|
type Error = (); |
|
|
|
|
#[inline] |
|
|
|
|
fn try_from(component: Component) -> Result<Self, Self::Error> { |
|
|
|
|
Self::from_bits(component.to_bits()).ok_or(()) |
|
|
|
|
if component.is_relation() { |
|
|
|
|
// SAFETY: If component is valid and a relation, bitwise conversion is valid.
|
|
|
|
|
Ok(unsafe { Self::from_bits_unchecked(component.to_bits()) }) |
|
|
|
|
} else { |
|
|
|
|
Err(()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -133,3 +142,12 @@ impl std::hash::Hash for Relation { |
|
|
|
|
self.to_bits().hash(state); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl std::fmt::Debug for Relation { |
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
|
|
|
|
f.debug_struct("Relation") |
|
|
|
|
.field("target", &self.target) |
|
|
|
|
.field("kind", &self.kind()) |
|
|
|
|
.finish() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|