feature gate sqlx for jid crate

This commit is contained in:
cel 🌸 2025-02-25 18:45:46 +00:00
parent 65e908e36c
commit 20fc4b1966
2 changed files with 10 additions and 9 deletions

View File

@ -3,5 +3,8 @@ name = "jid"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
[features]
sqlx = ["dep:sqlx"]
[dependencies] [dependencies]
sqlx = { version = "0.8.3", features = ["sqlite"] } sqlx = { version = "0.8.3", features = ["sqlite"], optional = true }

View File

@ -1,13 +1,9 @@
use std::{ use std::{borrow::Cow, error::Error, fmt::Display, str::FromStr};
borrow::Cow,
error::Error,
fmt::{Display, Write},
str::FromStr,
};
#[cfg(feature = "sqlx")]
use sqlx::Sqlite; use sqlx::Sqlite;
#[derive(PartialEq, Debug, Clone, sqlx::Type, sqlx::Encode, Eq, Hash)] #[derive(PartialEq, Debug, Clone, Eq, Hash)]
pub struct JID { pub struct JID {
// TODO: validate localpart (length, char] // TODO: validate localpart (length, char]
pub localpart: Option<String>, pub localpart: Option<String>,
@ -37,13 +33,14 @@ impl Display for JID {
} }
} }
// TODO: feature gate #[cfg(feature = "sqlx")]
impl sqlx::Type<Sqlite> for JID { impl sqlx::Type<Sqlite> for JID {
fn type_info() -> <Sqlite as sqlx::Database>::TypeInfo { fn type_info() -> <Sqlite as sqlx::Database>::TypeInfo {
<&str as sqlx::Type<Sqlite>>::type_info() <&str as sqlx::Type<Sqlite>>::type_info()
} }
} }
#[cfg(feature = "sqlx")]
impl sqlx::Decode<'_, Sqlite> for JID { impl sqlx::Decode<'_, Sqlite> for JID {
fn decode( fn decode(
value: <Sqlite as sqlx::Database>::ValueRef<'_>, value: <Sqlite as sqlx::Database>::ValueRef<'_>,
@ -54,6 +51,7 @@ impl sqlx::Decode<'_, Sqlite> for JID {
} }
} }
#[cfg(feature = "sqlx")]
impl sqlx::Encode<'_, Sqlite> for JID { impl sqlx::Encode<'_, Sqlite> for JID {
fn encode_by_ref( fn encode_by_ref(
&self, &self,