diff --git a/.scripts/internal-tests-0.sh b/.scripts/internal-tests-0.sh index b2aee8ca..72f332c2 100755 --- a/.scripts/internal-tests-0.sh +++ b/.scripts/internal-tests-0.sh @@ -56,6 +56,7 @@ $rt test-with-features wtx std $rt test-with-features wtx tokio $rt test-with-features wtx tokio-rustls $rt test-with-features wtx tracing +$rt test-with-features wtx uuid $rt test-with-features wtx web-socket $rt test-with-features wtx web-socket-handshake $rt test-with-features wtx webpki-roots diff --git a/Cargo.lock b/Cargo.lock index 6cf50cc1..fc6c9bc7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2493,6 +2493,7 @@ dependencies = [ "tracing", "tracing-subscriber", "tracing-tree", + "uuid", "webpki-roots", "x509-certificate", ] diff --git a/wtx/Cargo.toml b/wtx/Cargo.toml index e29c1e9d..00bd9bc8 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.0" } webpki-roots = { default-features = false, optional = true, version = "0.26" } x509-certificate = { default-features = false, optional = true, version = "0.24" } diff --git a/wtx/src/database/client/postgres/tys.rs b/wtx/src/database/client/postgres/tys.rs index 17065768..b8b86e12 100644 --- a/wtx/src/database/client/postgres/tys.rs +++ b/wtx/src/database/client/postgres/tys.rs @@ -836,3 +836,43 @@ mod serde_json { const TY: Ty = Ty::Jsonb; } } + +#[cfg(feature = "uuid")] +mod uuid { + use crate::database::{ + client::postgres::{DecodeValue, EncodeValue, Postgres, Ty}, + Decode, Encode, Typed, + }; + use uuid::Uuid; + + 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; + } + + test!(uuid, Uuid, Uuid::max()); +} diff --git a/wtx/src/error.rs b/wtx/src/error.rs index b0aebe63..bf259219 100644 --- a/wtx/src/error.rs +++ b/wtx/src/error.rs @@ -70,6 +70,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), @@ -441,6 +443,14 @@ impl From> for Error { } } +#[cfg(feature = "uuid")] +impl From for Error { + #[inline] + fn from(value: uuid::Error) -> Self { + Self::UuidError(value.into()) + } +} + #[cfg(feature = "x509-certificate")] impl From for Error { #[inline]