From 9e9c535d1080bfdbe404e45aa3c1fccf5d81bf19 Mon Sep 17 00:00:00 2001 From: Alexander Cyon Date: Fri, 22 Nov 2024 09:28:13 +0100 Subject: [PATCH] WIP --- crates/rules/src/rules/matrix.rs | 85 ++++++++++++++++++++++++++++++++ crates/rules/src/rules/mod.rs | 4 +- 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 crates/rules/src/rules/matrix.rs diff --git a/crates/rules/src/rules/matrix.rs b/crates/rules/src/rules/matrix.rs new file mode 100644 index 00000000..50f7d488 --- /dev/null +++ b/crates/rules/src/rules/matrix.rs @@ -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 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 {} + +// pub trait + +pub struct Matrix +where + P: RoleWithFactors, + R: RoleWithFactors, + C: RoleWithFactors { + p: PhantomData

, + r: PhantomData, + c: PhantomData, + } + +#[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); + } +} diff --git a/crates/rules/src/rules/mod.rs b/crates/rules/src/rules/mod.rs index 45d3692c..3930619f 100644 --- a/crates/rules/src/rules/mod.rs +++ b/crates/rules/src/rules/mod.rs @@ -1,3 +1,5 @@ mod error; +mod matrix; -pub use error::*; \ No newline at end of file +pub use error::*; +pub use matrix::*; \ No newline at end of file