|
|
@ -78,13 +78,9 @@ impl Relation { |
|
|
|
#[inline] |
|
|
|
#[inline] |
|
|
|
#[must_use] |
|
|
|
#[must_use] |
|
|
|
pub fn from_bits(bits: u64) -> Option<Self> { |
|
|
|
pub fn from_bits(bits: u64) -> Option<Self> { |
|
|
|
|
|
|
|
let kind = (bits >> 32) as u32; |
|
|
|
let target = bits 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) |
|
|
|
Self::new_checked(kind, target) |
|
|
|
} else { |
|
|
|
|
|
|
|
None |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[inline] |
|
|
|
#[inline] |
|
|
@ -98,12 +94,7 @@ impl TryFrom<Component> for Relation { |
|
|
|
type Error = (); |
|
|
|
type Error = (); |
|
|
|
#[inline] |
|
|
|
#[inline] |
|
|
|
fn try_from(component: Component) -> Result<Self, Self::Error> { |
|
|
|
fn try_from(component: Component) -> Result<Self, Self::Error> { |
|
|
|
if component.is_relation() { |
|
|
|
Self::from_bits(component.to_bits()).ok_or(()) |
|
|
|
// SAFETY: If component is valid and a relation, bitwise conversion is valid.
|
|
|
|
|
|
|
|
Ok(unsafe { Self::from_bits_unchecked(component.to_bits()) }) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Err(()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -142,12 +133,3 @@ impl std::hash::Hash for Relation { |
|
|
|
self.to_bits().hash(state); |
|
|
|
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() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|