From 1e3014a777805d3dcb691ee6ebe59c62f58f8222 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Sat, 31 Dec 2022 13:43:20 -0500 Subject: Remove sqlx dependency from webapp crate --- protocol/src/card.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'protocol/src') diff --git a/protocol/src/card.rs b/protocol/src/card.rs index 31d389a..b551a16 100644 --- a/protocol/src/card.rs +++ b/protocol/src/card.rs @@ -1,18 +1,17 @@ use anyhow::anyhow; pub(crate) use serde::{Deserialize, Serialize}; -use sqlx::encode::IsNull; -use sqlx::error::BoxDynError; -use sqlx::postgres::PgArgumentBuffer; -use sqlx::postgres::PgTypeInfo; -use sqlx::Postgres; -use sqlx::postgres::PgValueRef; -use strum_macros::FromRepr; +#[cfg(feature = "db")] +use sqlx::{ + encode::IsNull, error::BoxDynError, postgres::PgArgumentBuffer, + postgres::PgTypeInfo, postgres::PgValueRef, Postgres, +}; use std::fmt; use strum::EnumCount; use strum::IntoEnumIterator; use strum_macros::EnumCount; use strum_macros::EnumIter; +use strum_macros::FromRepr; #[derive( PartialOrd, @@ -78,19 +77,23 @@ impl fmt::Display for Suit { } } +#[cfg(feature = "db")] impl sqlx::Type for Rank { fn type_info() -> PgTypeInfo { >::type_info() } } +#[cfg(feature = "db")] impl sqlx::Decode<'_, Postgres> for Rank { fn decode(value: PgValueRef<'_>) -> Result { let value = >::decode(value)?; - Ok(Rank::from_repr(u8::try_from(value).expect("domain check")).expect("domain check")) + Ok(Rank::from_repr(u8::try_from(value).expect("domain check")) + .expect("domain check")) } } +#[cfg(feature = "db")] impl sqlx::Encode<'_, Postgres> for Rank { fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> IsNull { let pg_value = *self as i16; @@ -98,12 +101,14 @@ impl sqlx::Encode<'_, Postgres> for Rank { } } +#[cfg(feature = "db")] impl sqlx::Type for Suit { fn type_info() -> PgTypeInfo { <&str as sqlx::Type>::type_info() } } +#[cfg(feature = "db")] impl sqlx::Decode<'_, Postgres> for Suit { fn decode(value: PgValueRef<'_>) -> Result { let value = <&str as sqlx::Decode>::decode(value)?; @@ -117,6 +122,7 @@ impl sqlx::Decode<'_, Postgres> for Suit { } } +#[cfg(feature = "db")] impl sqlx::Encode<'_, Postgres> for Suit { fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> IsNull { let pg_value = match *self { -- cgit v1.2.3