yfunc_rust/yuid.rs
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 new() -> Self {
Self(Uuid::new_v4())
}
pub fn from_str(uuid_str: &str) -> YRes<YUid> {
let uid = Uuid::from_str(uuid_str).map_err(|err| {
err!(ParseError::"build Uuid from str": "parse uuid string failed", uuid_str, err)
})?;
Ok(Self(uid))
}
pub fn to_str(&self) -> String {
self.0.to_string()
}
}