Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajjon committed Nov 22, 2024
1 parent 8cc88f0 commit 9e9c535
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
85 changes: 85 additions & 0 deletions crates/rules/src/rules/matrix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
use std::marker::PhantomData;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RoleKind {
PrimaryRole,
RecoveryRole,
ConfirmationRole,
}

pub trait IsRole {
fn role_kind() -> RoleKind;
}

pub trait IsRoleObjectSafe {
fn get_role_kind(&self) -> RoleKind;
}

impl<T: IsRole> IsRoleObjectSafe for T {
fn get_role_kind(&self) -> RoleKind {
T::role_kind()
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TagPrimaryRole;

impl IsRole for TagPrimaryRole {
fn role_kind() -> RoleKind {
RoleKind::PrimaryRole
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TagConfirmationRole;

impl IsRole for TagConfirmationRole {
fn role_kind() -> RoleKind {
RoleKind::ConfirmationRole
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TagRecoveryRole;

impl IsRole for TagRecoveryRole {
fn role_kind() -> RoleKind {
RoleKind::RecoveryRole
}
}

// pub trait AnyRoleWithFactors: IsRoleObjectSafe {}

pub trait RoleWithFactors<RoleTag: IsRole> {}

// pub trait

pub struct Matrix<P, R, C>
where
P: RoleWithFactors<TagPrimaryRole>,
R: RoleWithFactors<TagRecoveryRole>,
C: RoleWithFactors<TagConfirmationRole> {
p: PhantomData<P>,
r: PhantomData<R>,
c: PhantomData<C>,
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn is_primary_role() {
assert_eq!(TagPrimaryRole::role_kind(), RoleKind::PrimaryRole);
}

#[test]
fn is_recovery_role() {
assert_eq!(TagRecoveryRole::role_kind(), RoleKind::RecoveryRole);
}

#[test]
fn is_confirmation_role() {
assert_eq!(TagConfirmationRole::role_kind(), RoleKind::ConfirmationRole);
}
}
4 changes: 3 additions & 1 deletion crates/rules/src/rules/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod error;
mod matrix;

pub use error::*;
pub use error::*;
pub use matrix::*;

0 comments on commit 9e9c535

Please sign in to comment.