#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub(crate) struct ProjectAuthority {
root: [u8; 32],
revision: [u8; 32],
}
impl ProjectAuthority {
pub(crate) fn new(root: [u8; 32], revision: [u8; 32]) -> Self {
Self { root, revision }
}
pub(crate) fn same_root(&self, other: &Self) -> bool {
self.root == other.root
}
pub(crate) fn same_revision(&self, other: &Self) -> bool {
self.revision == other.revision
}
}
pub(crate) fn index_of(value: u32) -> usize {
usize::try_from(value).unwrap_or(usize::MAX)
}
pub(crate) fn position(value: usize) -> u32 {
u32::try_from(value).unwrap_or(u32::MAX)
}
macro_rules! scoped_id {
($name:ident, $doc:expr) => {
#[doc = $doc]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct $name {
authority: $crate::resolution::identity::ProjectAuthority,
index: u32,
}
impl $name {
pub(super) fn new(
authority: $crate::resolution::identity::ProjectAuthority,
index: u32,
) -> Self {
Self { authority, index }
}
pub(super) fn authority(&self) -> $crate::resolution::identity::ProjectAuthority {
self.authority
}
pub(super) fn index(&self) -> u32 {
self.index
}
}
impl ::std::fmt::Debug for $name {
fn fmt(&self, formatter: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
::std::write!(
formatter,
::std::concat!(::std::stringify!($name), "({})"),
self.index
)
}
}
};
}
pub(crate) use scoped_id;