From e5024ff019e214ef17e72e492670884a178a3747 Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Wed, 12 Mar 2025 13:03:15 +0100 Subject: [PATCH] Add SpecialRoles with Demiurge --- src/lib.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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>; }