diff --git a/Cargo.lock b/Cargo.lock index 4de7eda..fbeaaae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1102,6 +1102,7 @@ dependencies = [ "bytes", "fallible-iterator", "postgres-protocol", + "uuid", ] [[package]] @@ -1277,6 +1278,15 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +[[package]] +name = "rust" +version = "0.1.0" +dependencies = [ + "postgres", + "upid 0.1.13", + "uuid", +] + [[package]] name = "rustc-demangle" version = "0.1.24" @@ -1773,6 +1783,16 @@ checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" [[package]] name = "upid" version = "0.0.999" +dependencies = [ + "rand", + "uuid", +] + +[[package]] +name = "upid" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "274cb48d804181f86b04059a9c13e8f37a263f1d9e4174527f2405c2aa048202" dependencies = [ "rand", ] @@ -1783,7 +1803,7 @@ version = "0.0.0" dependencies = [ "pgrx", "pgrx-tests", - "upid", + "upid 0.0.999", ] [[package]] diff --git a/upid_rs/Cargo.toml b/upid_rs/Cargo.toml index 6dda657..3137420 100644 --- a/upid_rs/Cargo.toml +++ b/upid_rs/Cargo.toml @@ -12,6 +12,7 @@ edition = "2021" [dependencies] rand = { version = "0.8" } +uuid = { version = "1", optional = true } [lib] name = "upid" diff --git a/upid_rs/src/lib.rs b/upid_rs/src/lib.rs index c2fcdbf..4441457 100644 --- a/upid_rs/src/lib.rs +++ b/upid_rs/src/lib.rs @@ -34,6 +34,8 @@ // https://github.com/dylanhart/ulid-rs mod b32; +#[cfg(feature = "uuid")] +mod uuid; pub use crate::b32::{DecodeError, ENCODE}; diff --git a/upid_rs/src/uuid.rs b/upid_rs/src/uuid.rs new file mode 100644 index 0000000..f4e3941 --- /dev/null +++ b/upid_rs/src/uuid.rs @@ -0,0 +1,30 @@ +//! Convert between Upid and Uuid. + +use crate::Upid; +use uuid::Uuid; + +impl From for Upid { + fn from(uuid: Uuid) -> Self { + Upid(uuid.as_u128()) + } +} + +impl From for Uuid { + fn from(upid: Upid) -> Self { + Uuid::from_u128(upid.0) + } +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn uuid_cycle() { + let want = Upid::new("user"); + let uuid: Uuid = want.into(); + let got: Upid = uuid.into(); + + assert_eq!(got, want) + } +}