Mercurial > core / rust/lib/obj/src/id.rs
changeset 17: |
c7165d93a9eb |
child: |
255000153a76 |
author: |
ellis <ellis@rwest.io> |
date: |
Sun, 22 Oct 2023 23:03:15 -0400 |
permissions: |
-rw-r--r-- |
description: |
add obj and net src |
1 //! rlib/obj/src/id.rs --- rlib::obj::id 3 //! primitive ID types. 6 pub use rusty_ulid::{self, Ulid}; 7 use std::{fmt, str::FromStr}; 11 /// Defines Identity-related behaviors 12 pub trait Identity: Sized { 13 /// return the hashed bytes of an ObjectId 17 #[derive(Debug, Copy, Clone, Eq, PartialEq)] 18 pub struct ObjectId(u128); 20 pub struct NameSpace { 21 pub prefix: Option<String>, 32 impl From<Uuid> for ObjectId { 33 fn from(uuid: Uuid) -> Self { 34 ObjectId(uuid.as_u128()) 38 impl From<Ulid> for ObjectId { 39 fn from(ulid: Ulid) -> Self { 40 ObjectId(u128::from(ulid)) 44 impl From<u128> for ObjectId { 45 fn from(src: u128) -> Self { 50 impl FromStr for ObjectId { 52 fn from_str(input: &str) -> std::result::Result<ObjectId, Self::Err> { 54 i => Ok(ObjectId(u128::from(Ulid::from_str(i).unwrap()))), 59 impl fmt::Display for ObjectId { 60 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 63 write!(f, "{}", Ulid::from(i))