#![warn(missing_docs)]
use std::fmt::Display;
use crate::schema::Value;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Uuid(pub String);
impl Uuid {
pub fn new(s: impl Into<String>) -> Self {
Uuid(s.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
pub fn into_string(self) -> String {
self.0
}
}
impl Display for Uuid {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl From<String> for Uuid {
fn from(s: String) -> Self {
Uuid(s)
}
}
impl From<&str> for Uuid {
fn from(s: &str) -> Self {
Uuid(s.to_string())
}
}
impl From<Uuid> for String {
fn from(uuid: Uuid) -> Self {
uuid.0
}
}
impl From<Uuid> for Value {
fn from(uuid: Uuid) -> Self {
Value::Uuid(uuid)
}
}
impl From<&Uuid> for Value {
fn from(uuid: &Uuid) -> Self {
Value::Uuid(uuid.clone())
}
}
impl TryFrom<Value> for Uuid {
type Error = ();
fn try_from(value: Value) -> Result<Self, Self::Error> {
match value {
Value::Uuid(uuid) => Ok(uuid),
Value::String(s) => Ok(Uuid(s)),
_ => Err(()),
}
}
}