summaryrefslogtreecommitdiff
path: root/protocol/src
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2022-12-31 13:43:20 -0500
committerKjetil Orbekk <kj@orbekk.com>2022-12-31 13:43:20 -0500
commit1e3014a777805d3dcb691ee6ebe59c62f58f8222 (patch)
tree938d14db72c52dd96f5345fb084fd603c9dcebeb /protocol/src
parent88366acba07b678466b42829887dcdda4f583686 (diff)
Remove sqlx dependency from webapp crate
Diffstat (limited to 'protocol/src')
-rw-r--r--protocol/src/card.rs22
1 files changed, 14 insertions, 8 deletions
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<Postgres> for Rank {
fn type_info() -> PgTypeInfo {
<i16 as sqlx::Type<Postgres>>::type_info()
}
}
+#[cfg(feature = "db")]
impl sqlx::Decode<'_, Postgres> for Rank {
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError> {
let value = <i16 as sqlx::Decode<Postgres>>::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<Postgres> for Suit {
fn type_info() -> PgTypeInfo {
<&str as sqlx::Type<Postgres>>::type_info()
}
}
+#[cfg(feature = "db")]
impl sqlx::Decode<'_, Postgres> for Suit {
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError> {
let value = <&str as sqlx::Decode<Postgres>>::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 {