yfunc_rust/
yuid.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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()
    }

}