Add pairing special role + some refactor

This commit is contained in:
NicolasCantu 2025-03-26 12:27:47 +01:00 committed by Nicolas Cantu
parent 87891a5017
commit 2e64835142

View File

@ -32,17 +32,24 @@ const PAIREDADDRESSES: &str = "pairedAddresses";
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub enum SpecialRoles { pub enum SpecialRoles {
DEMIURGE, // Only valid for the first state of a process Demiurge, // Only valid for the first state of a process
APOPHIS, // Users in this role have the power to destroy the process Pairing, // Special validation rules for pairing process
Apophis, // Users in this role have the power to destroy the process
} }
impl std::fmt::Display for SpecialRoles { impl std::fmt::Display for SpecialRoles {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let role_str = match self { write!(f, "{}", <&Self as Into<&str>>::into(self))
SpecialRoles::DEMIURGE => "demiurge", }
SpecialRoles::APOPHIS => "apophis", }
};
write!(f, "{}", role_str) impl From<&SpecialRoles> for &str {
fn from(value: &SpecialRoles) -> Self {
match value {
SpecialRoles::Demiurge => DEMIURGE,
SpecialRoles::Pairing => PAIRING,
SpecialRoles::Apophis => APOPHIS,
}
} }
} }
@ -51,9 +58,37 @@ impl FromStr for SpecialRoles {
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
match s { match s {
"demiurge" => Ok(SpecialRoles::DEMIURGE), DEMIURGE => Ok(SpecialRoles::Demiurge),
"apophis" => Ok(SpecialRoles::APOPHIS), PAIRING => Ok(SpecialRoles::Pairing),
_ => Err(format!("Invalid role: {}", s)), APOPHIS => Ok(SpecialRoles::Apophis),
_ => Err(format!("Invalid special role: {}", s)),
}
}
}
#[derive(Debug, PartialEq, Eq)]
pub enum ReservedFields {
PairedAddresses,
MemberPublicName,
}
impl From<&ReservedFields> for &str {
fn from(value: &ReservedFields) -> Self {
match value {
ReservedFields::MemberPublicName => MEMBERPUBLICNAME,
ReservedFields::PairedAddresses => PAIREDADDRESSES,
}
}
}
impl FromStr for ReservedFields {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
MEMBERPUBLICNAME => Ok(ReservedFields::MemberPublicName),
PAIREDADDRESSES => Ok(ReservedFields::PairedAddresses),
_ => Err(format!("Invalid field name: {}", s)),
} }
} }
} }