From 61b769b3c1ab0181b056f610168e5fc8be1cfa90 Mon Sep 17 00:00:00 2001 From: rasul Date: Tue, 7 Apr 2020 14:09:15 -0500 Subject: [PATCH] add a parse_str() method to Id --- src/id.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/id.rs b/src/id.rs index fe0b9eb..91bb2fd 100644 --- a/src/id.rs +++ b/src/id.rs @@ -10,6 +10,9 @@ use rusqlite::types::{FromSql, FromSqlError, FromSqlResult, ToSql, ToSqlOutput, use serde::{Deserialize, Serialize}; use uuid::Uuid; +use crate::result::RudeResult; +use crate::try_log; + /// Universally unique identifier #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub struct Id(Uuid); @@ -19,6 +22,14 @@ impl Id { pub fn new() -> Self { Self(Uuid::new_v4()) } + + pub fn parse_str(input: &str) -> RudeResult { + Ok(Id(try_log!( + Uuid::parse_str(input), + "Unable to parse Uuid from str: {}", + input + ))) + } } impl fmt::Display for Id {