Documentation
use std::str::FromStr;

use crate::prelude::*;
use uuid::Uuid;

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct YUid(Uuid);

impl YUid {

    pub fn origin(&self) -> Uuid {
        self.0
    }

    pub fn new() -> Self {
        Self(Uuid::new_v4())
    }

    pub fn from_str(uuid_str: &str) -> YRes<YUid> {
        let uid = Uuid::from_str(uuid_str).map_err(|e| {
            err!("build YUid from uuid string failed").trace(
                ctx!("build YUid from uuid string: Uuid::from_str() failed", uuid_str, e)
            )
        })?;
        Ok(Self(uid))
    }

    pub fn to_str(&self) -> String {
        self.0.to_string()
    }

}