Add pairing special role + some refactor
This commit is contained in:
parent
f762fb903c
commit
77618c4061
55
src/lib.rs
55
src/lib.rs
@ -32,17 +32,24 @@ const PAIREDADDRESSES: &str = "pairedAddresses";
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum SpecialRoles {
|
||||
DEMIURGE, // Only valid for the first state of a process
|
||||
APOPHIS, // Users in this role have the power to destroy the process
|
||||
Demiurge, // Only valid for the first state of a 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 {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let role_str = match self {
|
||||
SpecialRoles::DEMIURGE => "demiurge",
|
||||
SpecialRoles::APOPHIS => "apophis",
|
||||
};
|
||||
write!(f, "{}", role_str)
|
||||
write!(f, "{}", <&Self as Into<&str>>::into(self))
|
||||
}
|
||||
}
|
||||
|
||||
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> {
|
||||
match s {
|
||||
"demiurge" => Ok(SpecialRoles::DEMIURGE),
|
||||
"apophis" => Ok(SpecialRoles::APOPHIS),
|
||||
_ => Err(format!("Invalid role: {}", s)),
|
||||
DEMIURGE => Ok(SpecialRoles::Demiurge),
|
||||
PAIRING => Ok(SpecialRoles::Pairing),
|
||||
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)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user