use crate::StorageId;
use color_eyre::eyre::Result;
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Default, Serialize, Deserialize, Hash)]
pub struct RandomId(String);
impl RandomId {
pub fn new() -> Self {
Self(nanoid::nanoid!())
}
pub fn from_str(s: &str) -> Self {
Self(s.to_string())
}
pub fn value(&self) -> &str {
&self.0
}
}
impl StorageId for RandomId {
fn from_string(s: &str) -> Result<Self> {
Ok(Self(s.to_string()))
}
fn generate_new(_previous: Option<&Self>) -> Self {
Self::new()
}
fn is_valid_format(_s: &str) -> bool {
true
}
}
impl fmt::Display for RandomId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}