add a parse_str() method to Id

master
rasul 5 years ago
parent c963514967
commit 61b769b3c1

@ -10,6 +10,9 @@ use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSql, ToSqlOutput,
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use uuid::Uuid; use uuid::Uuid;
use crate::result::RudeResult;
use crate::try_log;
/// Universally unique identifier /// Universally unique identifier
#[derive(Clone, Copy, Debug, Deserialize, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub struct Id(Uuid); pub struct Id(Uuid);
@ -19,6 +22,14 @@ impl Id {
pub fn new() -> Self { pub fn new() -> Self {
Self(Uuid::new_v4()) Self(Uuid::new_v4())
} }
pub fn parse_str(input: &str) -> RudeResult<Self> {
Ok(Id(try_log!(
Uuid::parse_str(input),
"Unable to parse Uuid from str: {}",
input
)))
}
} }
impl fmt::Display for Id { impl fmt::Display for Id {

Loading…
Cancel
Save