diff --git a/src/lib.rs b/src/lib.rs index 8aae093..326d983 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ use std::fmt::Debug; +use std::str::FromStr; use std::sync::{Mutex, MutexGuard}; pub use aes_gcm; @@ -22,6 +23,31 @@ pub mod silentpayments; pub const MAX_PRD_PAYLOAD_SIZE: usize = u16::MAX as usize; // 64KiB sounds reasonable for now +#[derive(Debug, PartialEq, Eq)] +pub enum SpecialRoles { + DEMIURGE, +} + +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", + }; + write!(f, "{}", role_str) + } +} + +impl FromStr for SpecialRoles { + type Err = String; + + fn from_str(s: &str) -> Result { + match s { + "demiurge" => Ok(SpecialRoles::DEMIURGE), + _ => Err(format!("Invalid role: {}", s)), + } + } +} + pub trait MutexExt { fn lock_anyhow(&self) -> Result, anyhow::Error>; }