diff options
author | 2025-02-25 18:45:46 +0000 | |
---|---|---|
committer | 2025-02-25 18:45:46 +0000 | |
commit | 20fc4b196670c7f218abe87eba0fec43ed5068a6 (patch) | |
tree | 863d09f3bdbe23cd0045a777277a27be2743e242 | |
parent | 65e908e36c2f9f9badc235de7a40e15836c77a8c (diff) | |
download | luz-20fc4b196670c7f218abe87eba0fec43ed5068a6.tar.gz luz-20fc4b196670c7f218abe87eba0fec43ed5068a6.tar.bz2 luz-20fc4b196670c7f218abe87eba0fec43ed5068a6.zip |
feature gate sqlx for jid crate
-rw-r--r-- | jid/Cargo.toml | 5 | ||||
-rw-r--r-- | jid/src/lib.rs | 14 |
2 files changed, 10 insertions, 9 deletions
diff --git a/jid/Cargo.toml b/jid/Cargo.toml index 0d817c9..d5983ea 100644 --- a/jid/Cargo.toml +++ b/jid/Cargo.toml @@ -3,5 +3,8 @@ name = "jid" version = "0.1.0" edition = "2021" +[features] +sqlx = ["dep:sqlx"] + [dependencies] -sqlx = { version = "0.8.3", features = ["sqlite"] } +sqlx = { version = "0.8.3", features = ["sqlite"], optional = true } diff --git a/jid/src/lib.rs b/jid/src/lib.rs index 878b6f7..52b7173 100644 --- a/jid/src/lib.rs +++ b/jid/src/lib.rs @@ -1,13 +1,9 @@ -use std::{ - borrow::Cow, - error::Error, - fmt::{Display, Write}, - str::FromStr, -}; +use std::{borrow::Cow, error::Error, fmt::Display, str::FromStr}; +#[cfg(feature = "sqlx")] use sqlx::Sqlite; -#[derive(PartialEq, Debug, Clone, sqlx::Type, sqlx::Encode, Eq, Hash)] +#[derive(PartialEq, Debug, Clone, Eq, Hash)] pub struct JID { // TODO: validate localpart (length, char] pub localpart: Option<String>, @@ -37,13 +33,14 @@ impl Display for JID { } } -// TODO: feature gate +#[cfg(feature = "sqlx")] impl sqlx::Type<Sqlite> for JID { fn type_info() -> <Sqlite as sqlx::Database>::TypeInfo { <&str as sqlx::Type<Sqlite>>::type_info() } } +#[cfg(feature = "sqlx")] impl sqlx::Decode<'_, Sqlite> for JID { fn decode( 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 { fn encode_by_ref( &self, |