Our Personal Data Server from scratch!
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 56 lines 1.3 kB view raw
1use std::marker::PhantomData; 2 3use crate::DbError; 4 5#[derive(Debug)] 6pub struct ValidatedInviteCode<'a> { 7 code: &'a str, 8 _marker: PhantomData<&'a ()>, 9} 10 11impl<'a> ValidatedInviteCode<'a> { 12 pub fn new_validated(code: &'a str) -> Self { 13 Self { 14 code, 15 _marker: PhantomData, 16 } 17 } 18 19 pub fn code(&self) -> &str { 20 self.code 21 } 22} 23 24#[derive(Debug)] 25pub enum InviteCodeError { 26 NotFound, 27 ExhaustedUses, 28 Disabled, 29 DatabaseError(DbError), 30} 31 32impl std::fmt::Display for InviteCodeError { 33 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 34 match self { 35 Self::NotFound => write!(f, "Invite code not found"), 36 Self::ExhaustedUses => write!(f, "Invite code has no remaining uses"), 37 Self::Disabled => write!(f, "Invite code is disabled"), 38 Self::DatabaseError(e) => write!(f, "Database error: {}", e), 39 } 40 } 41} 42 43impl std::error::Error for InviteCodeError { 44 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { 45 match self { 46 Self::DatabaseError(e) => Some(e), 47 _ => None, 48 } 49 } 50} 51 52impl From<DbError> for InviteCodeError { 53 fn from(e: DbError) -> Self { 54 Self::DatabaseError(e) 55 } 56}