From c8a8cb4ec532cbf1a6821fba4b2084b4f0e7b4c0 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 9 Jan 2019 18:17:20 -0800 Subject: impl AsRef, From, Into for FatCatId --- rust/src/identifiers.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'rust/src') diff --git a/rust/src/identifiers.rs b/rust/src/identifiers.rs index 5cfa2fb6..e107d16f 100644 --- a/rust/src/identifiers.rs +++ b/rust/src/identifiers.rs @@ -4,7 +4,7 @@ use regex::Regex; use serde_json; use std::str::FromStr; use uuid::Uuid; -use std::fmt; +use std::{fmt, convert}; #[derive(Clone, Copy, PartialEq, Debug)] @@ -23,11 +23,29 @@ impl FromStr for FatCatId { } } +impl convert::AsRef for FatCatId { + fn as_ref(&self) -> &Uuid { + &self.0 + } +} + +impl convert::Into for FatCatId { + fn into(self) -> Uuid { + self.0 + } +} + +impl convert::From for FatCatId { + fn from(u: Uuid) -> FatCatId { + FatCatId(u) + } +} + impl FatCatId { pub fn to_uuid(&self) -> Uuid { self.0 } - // TODO: just make it u: Uuid and clone (not by ref) + // TODO: make it possible to just pass 'Uuid' in addition to '&Uuid' pub fn from_uuid(u: &Uuid) -> FatCatId { FatCatId(*u) } -- cgit v1.2.3