Simplify some utility functions
This commit is contained in:
parent
3a35343a34
commit
c9a59f4731
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -739,9 +739,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "instant"
|
||||
version = "0.1.11"
|
||||
version = "0.1.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "716d3d89f35ac6a34fd0eed635395f4c3b76fa889338a4632e5231a8684216bd"
|
||||
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
@ -1645,9 +1645,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||
|
||||
[[package]]
|
||||
name = "structopt"
|
||||
version = "0.3.23"
|
||||
version = "0.3.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bf9d950ef167e25e0bdb073cf1d68e9ad2795ac826f2f3f59647817cf23c0bfa"
|
||||
checksum = "40b9788f4202aa75c240ecc9c15c65185e6a39ccdeb0fd5d008b98825464c87c"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"lazy_static",
|
||||
@ -1656,9 +1656,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "structopt-derive"
|
||||
version = "0.4.16"
|
||||
version = "0.4.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "134d838a2c9943ac3125cf6df165eda53493451b719f3255b2a26b85f772d0ba"
|
||||
checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro-error",
|
||||
|
@ -38,21 +38,16 @@ use sqlx::{
|
||||
use url::Url;
|
||||
use uuid::Uuid;
|
||||
|
||||
fn into_user_limit(
|
||||
#[cfg(feature = "sqlite")]
|
||||
row: &SqliteRow,
|
||||
index: &str
|
||||
) -> SqlxResult<Vec<String>> {
|
||||
let row_value = row.try_get(index)?;
|
||||
from_sql_formatted_array(row_value, index).map(|i| i.collect())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn into_server_limit(
|
||||
fn into_limit<T>(
|
||||
#[cfg(feature = "sqlite")]
|
||||
row: &SqliteRow,
|
||||
index: &str
|
||||
) -> SqlxResult<Vec<Url>> {
|
||||
) -> SqlxResult<Vec<T>>
|
||||
where
|
||||
T: FromStr,
|
||||
<T as FromStr>::Err: Into<Box<dyn std::error::Error + Send + Sync>>,
|
||||
{
|
||||
Ok(from_sql_formatted_array(row.try_get(index)?, index)?.collect())
|
||||
}
|
||||
|
||||
@ -67,7 +62,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_sql_formatted_array<T>(raw: String, index: &str) -> SqlxResult<impl Iterator<Item = T>>
|
||||
where
|
||||
T: FromStr,
|
||||
@ -263,15 +257,15 @@ impl PrivacyPreferences {
|
||||
) -> SqlxResult<Self> {
|
||||
Ok(PrivacyPreferences {
|
||||
discovery: row.try_get("discovery")?,
|
||||
discovery_user_limit: into_user_limit(row, "discovery_user_limit")?,
|
||||
discovery_server_limit: into_server_limit(row, "discovery_server_limit")?,
|
||||
discovery_user_limit: into_limit(row, "discovery_user_limit")?,
|
||||
discovery_server_limit: into_limit(row, "discovery_server_limit")?,
|
||||
last_seen: row.try_get("last_seen")?,
|
||||
last_seen_user_limit: into_user_limit(row, "last_seen_user_limit")?,
|
||||
last_seen_server_limit: into_server_limit(row, "last_seen_server_limit")?,
|
||||
last_seen_user_limit: into_limit(row, "last_seen_user_limit")?,
|
||||
last_seen_server_limit: into_limit(row, "last_seen_server_limit")?,
|
||||
last_seen_course: row.try_get("last_seen_course")?,
|
||||
info: row.try_get("info")?,
|
||||
info_user_limit: into_user_limit(row, "info_user_limit")?,
|
||||
info_server_limit: into_server_limit(row, "info_server_limit")?,
|
||||
info_user_limit: into_limit(row, "info_user_limit")?,
|
||||
info_server_limit: into_limit(row, "info_server_limit")?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -283,7 +277,7 @@ impl FromRow<'_, SqliteRow> for PrivacyPreferences {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, GraphQLObject, Decode, Encode, FromRow)]
|
||||
#[derive(Clone, Copy, Debug, Default, GraphQLObject, Type, FromRow)]
|
||||
pub struct NotificationPreferences {
|
||||
lock_details: bool,
|
||||
do_not_disturb: bool,
|
||||
@ -403,7 +397,7 @@ impl Query {
|
||||
security_preferences,
|
||||
external_servers_preferences: ExternalServersPreferences {
|
||||
external_servers: external_servers_preferences.try_get("external_servers")?,
|
||||
external_servers_limit: into_server_limit(&external_servers_preferences, "external_servers_limit")?,
|
||||
external_servers_limit: into_limit(&external_servers_preferences, "external_servers_limit")?,
|
||||
privacy_preferences: external_servers_privacy_preferences,
|
||||
},
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user