fistinc-auth 0.1.0

Paging types for Fist Inc bank
Documentation
use std::convert::TryFrom;
use serde::{Serialize, Deserialize};

#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
pub enum Role {
    Administrator,
    Default,
}

impl TryFrom<String> for Role {
    type Error = &'static str;

    fn try_from(value: String) -> Result<Self, Self::Error> {
        Self::try_from(&*value)
    }
}

impl TryFrom<&str> for Role {
    type Error = &'static str;

    fn try_from(value: &str) -> Result<Self, Self::Error> {
        match value {
            "Administrator" => Ok(Role::Administrator),
            "Client" => Ok(Role::Default),
            _ => Err("Cant convert to Role"),
        }
    }
}

impl ToString for Role {
    fn to_string(&self) -> String {
        let str = match self {
            Role::Administrator => "Administrator",
            Role::Default => "Client",
        };
        str.to_string()
    }
}