diff --git a/Cargo.lock b/Cargo.lock index 5b3d128a..7d0142af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2494,6 +2494,7 @@ dependencies = [ "tracing", "tracing-subscriber", "tracing-tree", + "uuid", "webpki-roots", "x509-certificate", ] diff --git a/wtx/Cargo.toml b/wtx/Cargo.toml index 6b4b668c..122fcef2 100644 --- a/wtx/Cargo.toml +++ b/wtx/Cargo.toml @@ -41,6 +41,7 @@ tokio-rustls = { default-features = false, features = ["ring"], optional = true, tracing = { default-features = false, features = ["attributes"], optional = true, version = "0.1" } tracing-subscriber = { default-features = false, features = ["env-filter", "fmt"], optional = true, version = "0.3" } tracing-tree = { default-features = false, optional = true, version = "0.4" } +uuid = { default-features = false, optional = true, version = "1.11.0" } webpki-roots = { default-features = false, optional = true, version = "0.26" } x509-certificate = { default-features = false, optional = true, version = "0.24" } @@ -114,6 +115,7 @@ std = [ tls = [] tokio = ["std", "dep:tokio"] tokio-rustls = ["ring", "rustls", "dep:rustls-pemfile", "rustls-pki-types", "tokio", "dep:tokio-rustls"] +uuid = ["dep:uuid"] web-socket = ["http"] web-socket-handshake = ["base64", "httparse", "sha1", "web-socket"] diff --git a/wtx/src/database/client/postgres/tys.rs b/wtx/src/database/client/postgres/tys.rs index 17065768..4aaa2972 100644 --- a/wtx/src/database/client/postgres/tys.rs +++ b/wtx/src/database/client/postgres/tys.rs @@ -836,3 +836,50 @@ mod serde_json { const TY: Ty = Ty::Jsonb; } } + +#[cfg(feature = "uuid")] +mod uuid { + use std::prelude::v1::Box; + + use uuid::{Error as UuidError, Uuid}; + + use crate::database::{ + client::postgres::{DecodeValue, EncodeValue, Postgres, Ty}, + Decode, Encode, Typed, + }; + + impl<'de, E> Decode<'de, Postgres> for Uuid + where + E: From, + { + #[inline] + fn decode(input: &DecodeValue<'de>) -> Result { + let elem = Uuid::from_slice(input.bytes()).map_err(Into::into)?; + Ok(elem) + } + } + + impl Encode> for Uuid + where + E: From, + { + #[inline] + fn encode(&self, ev: &mut EncodeValue<'_, '_>) -> Result<(), E> { + ev.fbw()._extend_from_slice(self.as_bytes()).map_err(Into::into)?; + Ok(()) + } + } + + impl Typed> for Uuid + where + E: From, + { + const TY: Ty = Ty::Uuid; + } + + impl From for crate::Error { + fn from(value: UuidError) -> Self { + Self::UuidError(Box::new(value)) + } + } +} diff --git a/wtx/src/error.rs b/wtx/src/error.rs index e2597c82..de662181 100644 --- a/wtx/src/error.rs +++ b/wtx/src/error.rs @@ -72,6 +72,8 @@ pub enum Error { TryInitError(tracing_subscriber::util::TryInitError), #[cfg(feature = "std")] TryLockError(std::sync::TryLockError<()>), + #[cfg(feature = "uuid")] + UuidError(Box), #[cfg(feature = "x509-certificate")] X509CertificateError(Box),