From 8fb7b1d10f2ae21a439da5ae21aecc7612a6c2f9 Mon Sep 17 00:00:00 2001 From: Tamo Date: Mon, 13 Feb 2023 18:45:13 +0100 Subject: [PATCH] bump deserr --- Cargo.lock | 53 ++++++++++++++----- meilisearch-types/Cargo.toml | 2 +- .../src/deserr/error_messages.rs | 10 ++-- meilisearch-types/src/deserr/mod.rs | 9 ++-- meilisearch-types/src/deserr/query_params.rs | 4 +- meilisearch-types/src/error.rs | 8 +-- meilisearch-types/src/index_uid.rs | 6 +-- meilisearch-types/src/index_uid_pattern.rs | 6 +-- meilisearch-types/src/keys.rs | 16 +++--- meilisearch-types/src/settings.rs | 21 ++++---- meilisearch-types/src/star_or.rs | 14 +++-- meilisearch/Cargo.toml | 2 +- meilisearch/src/extractors/json.rs | 6 +-- .../src/extractors/query_parameters.rs | 6 +-- meilisearch/src/routes/api_key.rs | 4 +- meilisearch/src/routes/indexes/documents.rs | 8 +-- meilisearch/src/routes/indexes/mod.rs | 8 +-- meilisearch/src/routes/indexes/search.rs | 2 +- meilisearch/src/routes/swap_indexes.rs | 4 +- meilisearch/src/routes/tasks.rs | 36 +++++++------ meilisearch/src/search.rs | 6 +-- milli/Cargo.toml | 2 +- milli/src/update/settings.rs | 6 +-- 23 files changed, 137 insertions(+), 102 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c44891518..5aa355d73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -36,9 +36,9 @@ dependencies = [ [[package]] name = "actix-http" -version = "3.2.2" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c83abf9903e1f0ad9973cc4f7b9767fd5a03a583f51a5b7a339e07987cd2724" +checksum = "0070905b2c4a98d184c4e81025253cb192aa8a73827553f38e9410801ceb35bb" dependencies = [ "actix-codec", "actix-rt", @@ -46,7 +46,7 @@ dependencies = [ "actix-tls", "actix-utils", "ahash", - "base64 0.13.1", + "base64 0.21.0", "bitflags", "brotli", "bytes", @@ -68,7 +68,10 @@ dependencies = [ "rand", "sha1", "smallvec", + "tokio", + "tokio-util", "tracing", + "zstd 0.12.3+zstd.1.5.2", ] [[package]] @@ -164,9 +167,9 @@ dependencies = [ [[package]] name = "actix-web" -version = "4.2.1" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d48f7b6534e06c7bfc72ee91db7917d4af6afe23e7d223b51e68fffbb21e96b9" +checksum = "464e0fddc668ede5f26ec1f9557a8d44eda948732f40c6b0ad79126930eb775f" dependencies = [ "actix-codec", "actix-http", @@ -1110,20 +1113,23 @@ dependencies = [ [[package]] name = "deserr" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28380303ca15ec07e1d5b079baf19cf849b09edad5cab219c1c51b2bd07523de" +checksum = "a13eed41ca58d9dc99e2c67e1a5f50507dfa1b123cc4a942c81c49707bd347f0" dependencies = [ + "actix-web", "deserr-internal", + "futures", "serde-cs", "serde_json", + "strsim", ] [[package]] name = "deserr-internal" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "860928cd8af78d223a3d70dd581f21d7c3de8aa2eecd938e0c0a399ded7c1451" +checksum = "4d5412186d7149542b09319901d28b3c7d1f714a61d0c5d48a50560d09573ae4" dependencies = [ "convert_case 0.5.0", "proc-macro2", @@ -4423,7 +4429,7 @@ dependencies = [ "pbkdf2", "sha1", "time", - "zstd", + "zstd 0.11.2+zstd.1.5.2", ] [[package]] @@ -4432,7 +4438,16 @@ version = "0.11.2+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" dependencies = [ - "zstd-safe", + "zstd-safe 5.0.2+zstd.1.5.2", +] + +[[package]] +name = "zstd" +version = "0.12.3+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76eea132fb024e0e13fd9c2f5d5d595d8a967aa72382ac2f9d39fcc95afd0806" +dependencies = [ + "zstd-safe 6.0.4+zstd.1.5.4", ] [[package]] @@ -4446,10 +4461,20 @@ dependencies = [ ] [[package]] -name = "zstd-sys" -version = "2.0.5+zstd.1.5.2" +name = "zstd-safe" +version = "6.0.4+zstd.1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edc50ffce891ad571e9f9afe5039c4837bede781ac4bb13052ed7ae695518596" +checksum = "7afb4b54b8910cf5447638cb54bf4e8a65cbedd783af98b98c62ffe91f185543" +dependencies = [ + "libc", + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.7+zstd.1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94509c3ba2fe55294d752b79842c530ccfab760192521df74a081a78d2b3c7f5" dependencies = [ "cc", "libc", diff --git a/meilisearch-types/Cargo.toml b/meilisearch-types/Cargo.toml index f62202f76..021c44ea0 100644 --- a/meilisearch-types/Cargo.toml +++ b/meilisearch-types/Cargo.toml @@ -9,7 +9,7 @@ actix-web = { version = "4.2.1", default-features = false } anyhow = "1.0.65" convert_case = "0.6.0" csv = "1.1.6" -deserr = "0.3.0" +deserr = "0.4.0" either = { version = "1.6.1", features = ["serde"] } enum-iterator = "1.1.3" file-store = { path = "../file-store" } diff --git a/meilisearch-types/src/deserr/error_messages.rs b/meilisearch-types/src/deserr/error_messages.rs index 7e288085d..f17263813 100644 --- a/meilisearch-types/src/deserr/error_messages.rs +++ b/meilisearch-types/src/deserr/error_messages.rs @@ -6,6 +6,8 @@ We try to: 2. Use the correct terms depending on the format of the request (json/query param) 3. Categorise the type of the error (e.g. missing field, wrong value type, unexpected error, etc.) */ +use std::ops::ControlFlow; + use deserr::{ErrorKind, IntoValue, ValueKind, ValuePointerRef}; use super::{DeserrJsonError, DeserrQueryParamError}; @@ -129,7 +131,7 @@ impl deserr::DeserializeError for DeserrJsonError { _self_: Option, error: deserr::ErrorKind, location: ValuePointerRef, - ) -> Result { + ) -> ControlFlow { let mut message = String::new(); message.push_str(&match error { @@ -175,7 +177,7 @@ impl deserr::DeserializeError for DeserrJsonError { } }); - Err(DeserrJsonError::new(message, C::default().error_code())) + ControlFlow::Break(DeserrJsonError::new(message, C::default().error_code())) } } @@ -222,7 +224,7 @@ impl deserr::DeserializeError for DeserrQueryParamError< _self_: Option, error: deserr::ErrorKind, location: ValuePointerRef, - ) -> Result { + ) -> ControlFlow { let mut message = String::new(); message.push_str(&match error { @@ -268,7 +270,7 @@ impl deserr::DeserializeError for DeserrQueryParamError< } }); - Err(DeserrQueryParamError::new(message, C::default().error_code())) + ControlFlow::Break(DeserrQueryParamError::new(message, C::default().error_code())) } } diff --git a/meilisearch-types/src/deserr/mod.rs b/meilisearch-types/src/deserr/mod.rs index c15b2c3a0..49474a9e6 100644 --- a/meilisearch-types/src/deserr/mod.rs +++ b/meilisearch-types/src/deserr/mod.rs @@ -1,6 +1,7 @@ use std::convert::Infallible; use std::fmt; use std::marker::PhantomData; +use std::ops::ControlFlow; use deserr::{DeserializeError, MergeWithError, ValuePointerRef}; @@ -64,8 +65,8 @@ impl _self_: Option, other: DeserrError, _merge_location: ValuePointerRef, - ) -> Result { - Err(DeserrError { msg: other.msg, code: other.code, _phantom: PhantomData }) + ) -> ControlFlow { + ControlFlow::Break(DeserrError { msg: other.msg, code: other.code, _phantom: PhantomData }) } } @@ -74,7 +75,7 @@ impl MergeWithError for DeserrError< _self_: Option, _other: Infallible, _merge_location: ValuePointerRef, - ) -> Result { + ) -> ControlFlow { unreachable!() } } @@ -112,7 +113,7 @@ macro_rules! merge_with_error_impl_take_error_message { _self_: Option, other: $err_type, merge_location: ValuePointerRef, - ) -> Result { + ) -> ControlFlow { DeserrError::::error::( None, deserr::ErrorKind::Unexpected { msg: other.to_string() }, diff --git a/meilisearch-types/src/deserr/query_params.rs b/meilisearch-types/src/deserr/query_params.rs index 28629aa1b..06d83747c 100644 --- a/meilisearch-types/src/deserr/query_params.rs +++ b/meilisearch-types/src/deserr/query_params.rs @@ -15,7 +15,7 @@ use std::convert::Infallible; use std::ops::Deref; use std::str::FromStr; -use deserr::{DeserializeError, DeserializeFromValue, MergeWithError, ValueKind}; +use deserr::{DeserializeError, Deserr, MergeWithError, ValueKind}; use super::{DeserrParseBoolError, DeserrParseIntError}; use crate::error::unwrap_any; @@ -38,7 +38,7 @@ impl Deref for Param { } } -impl DeserializeFromValue for Param +impl Deserr for Param where E: DeserializeError + MergeWithError, T: FromQueryParameter, diff --git a/meilisearch-types/src/error.rs b/meilisearch-types/src/error.rs index 39d9a1551..d83bf7eb9 100644 --- a/meilisearch-types/src/error.rs +++ b/meilisearch-types/src/error.rs @@ -382,10 +382,12 @@ impl ErrorCode for io::Error { } /// Unwrap a result, either its Ok or Err value. -pub fn unwrap_any(any: Result) -> T { +pub fn unwrap_any(any: std::ops::ControlFlow) -> T { + use std::ops::ControlFlow::*; + match any { - Ok(any) => any, - Err(any) => any, + Continue(any) => any, + Break(any) => any, } } diff --git a/meilisearch-types/src/index_uid.rs b/meilisearch-types/src/index_uid.rs index 2f3f6e5df..341ab02cb 100644 --- a/meilisearch-types/src/index_uid.rs +++ b/meilisearch-types/src/index_uid.rs @@ -2,14 +2,14 @@ use std::error::Error; use std::fmt; use std::str::FromStr; -use deserr::DeserializeFromValue; +use deserr::Deserr; use crate::error::{Code, ErrorCode}; /// An index uid is composed of only ascii alphanumeric characters, - and _, between 1 and 400 /// bytes long -#[derive(Debug, Clone, PartialEq, Eq, DeserializeFromValue)] -#[deserr(from(String) = IndexUid::try_from -> IndexUidFormatError)] +#[derive(Debug, Clone, PartialEq, Eq, Deserr)] +#[deserr(try_from(String) = IndexUid::try_from -> IndexUidFormatError)] pub struct IndexUid(String); impl IndexUid { diff --git a/meilisearch-types/src/index_uid_pattern.rs b/meilisearch-types/src/index_uid_pattern.rs index 99537b22f..baf0249e2 100644 --- a/meilisearch-types/src/index_uid_pattern.rs +++ b/meilisearch-types/src/index_uid_pattern.rs @@ -4,7 +4,7 @@ use std::fmt; use std::ops::Deref; use std::str::FromStr; -use deserr::DeserializeFromValue; +use deserr::Deserr; use serde::{Deserialize, Serialize}; use crate::error::{Code, ErrorCode}; @@ -12,8 +12,8 @@ use crate::index_uid::{IndexUid, IndexUidFormatError}; /// An index uid pattern is composed of only ascii alphanumeric characters, - and _, between 1 and 400 /// bytes long and optionally ending with a *. -#[derive(Serialize, Deserialize, DeserializeFromValue, Debug, Clone, PartialEq, Eq, Hash)] -#[deserr(from(&String) = FromStr::from_str -> IndexUidPatternFormatError)] +#[derive(Serialize, Deserialize, Deserr, Debug, Clone, PartialEq, Eq, Hash)] +#[deserr(try_from(&String) = FromStr::from_str -> IndexUidPatternFormatError)] pub struct IndexUidPattern(String); impl IndexUidPattern { diff --git a/meilisearch-types/src/keys.rs b/meilisearch-types/src/keys.rs index 804ee19c6..7478391ba 100644 --- a/meilisearch-types/src/keys.rs +++ b/meilisearch-types/src/keys.rs @@ -2,7 +2,7 @@ use std::convert::Infallible; use std::hash::Hash; use std::str::FromStr; -use deserr::{DeserializeError, DeserializeFromValue, MergeWithError, ValuePointerRef}; +use deserr::{DeserializeError, Deserr, MergeWithError, ValuePointerRef}; use enum_iterator::Sequence; use milli::update::Setting; use serde::{Deserialize, Serialize}; @@ -24,7 +24,7 @@ impl MergeWithError for Dese _self_: Option, other: IndexUidPatternFormatError, merge_location: deserr::ValuePointerRef, - ) -> std::result::Result { + ) -> std::ops::ControlFlow { DeserrError::error::( None, deserr::ErrorKind::Unexpected { msg: other.to_string() }, @@ -33,20 +33,20 @@ impl MergeWithError for Dese } } -#[derive(Debug, DeserializeFromValue)] +#[derive(Debug, Deserr)] #[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)] pub struct CreateApiKey { #[deserr(default, error = DeserrJsonError)] pub description: Option, #[deserr(default, error = DeserrJsonError)] pub name: Option, - #[deserr(default = Uuid::new_v4(), error = DeserrJsonError, from(&String) = Uuid::from_str -> uuid::Error)] + #[deserr(default = Uuid::new_v4(), error = DeserrJsonError, try_from(&String) = Uuid::from_str -> uuid::Error)] pub uid: KeyId, #[deserr(error = DeserrJsonError, missing_field_error = DeserrJsonError::missing_api_key_actions)] pub actions: Vec, #[deserr(error = DeserrJsonError, missing_field_error = DeserrJsonError::missing_api_key_indexes)] pub indexes: Vec, - #[deserr(error = DeserrJsonError, from(Option) = parse_expiration_date -> ParseOffsetDateTimeError, missing_field_error = DeserrJsonError::missing_api_key_expires_at)] + #[deserr(error = DeserrJsonError, try_from(Option) = parse_expiration_date -> ParseOffsetDateTimeError, missing_field_error = DeserrJsonError::missing_api_key_expires_at)] pub expires_at: Option, } @@ -87,7 +87,7 @@ fn deny_immutable_fields_api_key( } } -#[derive(Debug, DeserializeFromValue)] +#[derive(Debug, Deserr)] #[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields = deny_immutable_fields_api_key)] pub struct PatchApiKey { #[deserr(default, error = DeserrJsonError)] @@ -182,9 +182,7 @@ fn parse_expiration_date( } } -#[derive( - Copy, Clone, Serialize, Deserialize, Debug, Eq, PartialEq, Hash, Sequence, DeserializeFromValue, -)] +#[derive(Copy, Clone, Serialize, Deserialize, Debug, Eq, PartialEq, Hash, Sequence, Deserr)] #[repr(u8)] pub enum Action { #[serde(rename = "*")] diff --git a/meilisearch-types/src/settings.rs b/meilisearch-types/src/settings.rs index b4ab1eff6..c7023bb10 100644 --- a/meilisearch-types/src/settings.rs +++ b/meilisearch-types/src/settings.rs @@ -3,9 +3,10 @@ use std::convert::Infallible; use std::fmt; use std::marker::PhantomData; use std::num::NonZeroUsize; +use std::ops::ControlFlow; use std::str::FromStr; -use deserr::{DeserializeError, DeserializeFromValue, ErrorKind, MergeWithError, ValuePointerRef}; +use deserr::{DeserializeError, Deserr, ErrorKind, MergeWithError, ValuePointerRef}; use fst::IntoStreamer; use milli::update::Setting; use milli::{Criterion, CriterionError, Index, DEFAULT_VALUES_PER_FACET}; @@ -41,7 +42,7 @@ pub struct Checked; #[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq)] pub struct Unchecked; -impl DeserializeFromValue for Unchecked +impl Deserr for Unchecked where E: DeserializeError, { @@ -65,7 +66,7 @@ fn validate_min_word_size_for_typo_setting( Ok(s) } -#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, DeserializeFromValue)] +#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, Deserr)] #[serde(deny_unknown_fields, rename_all = "camelCase")] #[deserr(deny_unknown_fields, rename_all = camelCase, validate = validate_min_word_size_for_typo_setting -> DeserrJsonError)] pub struct MinWordSizeTyposSetting { @@ -77,7 +78,7 @@ pub struct MinWordSizeTyposSetting { pub two_typos: Setting, } -#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, DeserializeFromValue)] +#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, Deserr)] #[serde(deny_unknown_fields, rename_all = "camelCase")] #[deserr(deny_unknown_fields, rename_all = camelCase, where_predicate = __Deserr_E: deserr::MergeWithError>)] pub struct TypoSettings { @@ -95,7 +96,7 @@ pub struct TypoSettings { pub disable_on_attributes: Setting>, } -#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, DeserializeFromValue)] +#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, Deserr)] #[serde(deny_unknown_fields, rename_all = "camelCase")] #[deserr(rename_all = camelCase, deny_unknown_fields)] pub struct FacetingSettings { @@ -104,7 +105,7 @@ pub struct FacetingSettings { pub max_values_per_facet: Setting, } -#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, DeserializeFromValue)] +#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, Deserr)] #[serde(deny_unknown_fields, rename_all = "camelCase")] #[deserr(rename_all = camelCase, deny_unknown_fields)] pub struct PaginationSettings { @@ -118,7 +119,7 @@ impl MergeWithError for DeserrJsonError, other: milli::CriterionError, merge_location: ValuePointerRef, - ) -> Result { + ) -> ControlFlow { Self::error::( None, ErrorKind::Unexpected { msg: other.to_string() }, @@ -130,7 +131,7 @@ impl MergeWithError for DeserrJsonError` from a `Settings`. -#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, DeserializeFromValue)] +#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, Deserr)] #[serde( deny_unknown_fields, rename_all = "camelCase", @@ -509,8 +510,8 @@ pub fn settings( }) } -#[derive(Debug, Clone, PartialEq, Eq, DeserializeFromValue)] -#[deserr(from(&String) = FromStr::from_str -> CriterionError)] +#[derive(Debug, Clone, PartialEq, Eq, Deserr)] +#[deserr(try_from(&String) = FromStr::from_str -> CriterionError)] pub enum RankingRuleView { /// Sorted by decreasing number of matched query terms. /// Query words at the front of an attribute is considered better than if it was at the back. diff --git a/meilisearch-types/src/star_or.rs b/meilisearch-types/src/star_or.rs index 135f610c4..0f3ef10fb 100644 --- a/meilisearch-types/src/star_or.rs +++ b/meilisearch-types/src/star_or.rs @@ -1,8 +1,9 @@ use std::fmt; use std::marker::PhantomData; +use std::ops::ControlFlow; use std::str::FromStr; -use deserr::{DeserializeError, DeserializeFromValue, MergeWithError, ValueKind}; +use deserr::{DeserializeError, Deserr, MergeWithError, ValueKind}; use serde::de::Visitor; use serde::{Deserialize, Deserializer, Serialize, Serializer}; @@ -111,7 +112,7 @@ where } } -impl DeserializeFromValue for StarOr +impl Deserr for StarOr where T: FromStr, E: DeserializeError + MergeWithError, @@ -191,7 +192,7 @@ where } } -impl DeserializeFromValue for OptionStarOr +impl Deserr for OptionStarOr where E: DeserializeError + MergeWithError, T: FromQueryParameter, @@ -271,7 +272,7 @@ impl OptionStarOrList { } } -impl DeserializeFromValue for OptionStarOrList +impl Deserr for OptionStarOrList where E: DeserializeError + MergeWithError, T: FromQueryParameter, @@ -299,7 +300,10 @@ where Err(e) => { let location = if len_cs > 1 { location.push_index(i) } else { location }; - error = Some(E::merge(error, e, location)?); + error = match E::merge(error, e, location) { + ControlFlow::Continue(e) => Some(e), + ControlFlow::Break(e) => return Err(e), + }; } } } diff --git a/meilisearch/Cargo.toml b/meilisearch/Cargo.toml index dba645665..b6410f7cb 100644 --- a/meilisearch/Cargo.toml +++ b/meilisearch/Cargo.toml @@ -19,7 +19,7 @@ byte-unit = { version = "4.0.14", default-features = false, features = ["std", " bytes = "1.2.1" clap = { version = "4.0.9", features = ["derive", "env"] } crossbeam-channel = "0.5.6" -deserr = "0.3.0" +deserr = "0.4.0" dump = { path = "../dump" } either = "1.8.0" env_logger = "0.9.1" diff --git a/meilisearch/src/extractors/json.rs b/meilisearch/src/extractors/json.rs index e2418c9fb..c59af14db 100644 --- a/meilisearch/src/extractors/json.rs +++ b/meilisearch/src/extractors/json.rs @@ -7,7 +7,7 @@ use std::task::{Context, Poll}; use actix_web::dev::Payload; use actix_web::web::Json; use actix_web::{FromRequest, HttpRequest}; -use deserr::{DeserializeError, DeserializeFromValue}; +use deserr::{DeserializeError, Deserr}; use futures::ready; use meilisearch_types::error::{ErrorCode, ResponseError}; @@ -33,7 +33,7 @@ impl ValidatedJson { impl FromRequest for ValidatedJson where E: DeserializeError + ErrorCode + std::error::Error + 'static, - T: DeserializeFromValue, + T: Deserr, { type Error = actix_web::Error; type Future = ValidatedJsonExtractFut; @@ -54,7 +54,7 @@ pub struct ValidatedJsonExtractFut { impl Future for ValidatedJsonExtractFut where - T: DeserializeFromValue, + T: Deserr, E: DeserializeError + ErrorCode + std::error::Error + 'static, { type Output = Result, actix_web::Error>; diff --git a/meilisearch/src/extractors/query_parameters.rs b/meilisearch/src/extractors/query_parameters.rs index 99c76f3aa..39b833062 100644 --- a/meilisearch/src/extractors/query_parameters.rs +++ b/meilisearch/src/extractors/query_parameters.rs @@ -6,7 +6,7 @@ use std::{fmt, ops}; use actix_http::Payload; use actix_utils::future::{err, ok, Ready}; use actix_web::{FromRequest, HttpRequest}; -use deserr::{DeserializeError, DeserializeFromValue}; +use deserr::{DeserializeError, Deserr}; use meilisearch_types::error::{Code, ErrorCode, ResponseError}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] @@ -21,7 +21,7 @@ impl QueryParameter { impl QueryParameter where - T: DeserializeFromValue, + T: Deserr, E: DeserializeError + ErrorCode + std::error::Error + 'static, { pub fn from_query(query_str: &str) -> Result { @@ -57,7 +57,7 @@ impl fmt::Display for QueryParameter { impl FromRequest for QueryParameter where - T: DeserializeFromValue, + T: Deserr, E: DeserializeError + ErrorCode + std::error::Error + 'static, { type Error = actix_web::Error; diff --git a/meilisearch/src/routes/api_key.rs b/meilisearch/src/routes/api_key.rs index efc591d54..096aa7df0 100644 --- a/meilisearch/src/routes/api_key.rs +++ b/meilisearch/src/routes/api_key.rs @@ -1,7 +1,7 @@ use std::str; use actix_web::{web, HttpRequest, HttpResponse}; -use deserr::DeserializeFromValue; +use deserr::Deserr; use meilisearch_auth::error::AuthControllerError; use meilisearch_auth::AuthController; use meilisearch_types::deserr::query_params::Param; @@ -51,7 +51,7 @@ pub async fn create_api_key( Ok(HttpResponse::Created().json(res)) } -#[derive(DeserializeFromValue, Debug, Clone, Copy)] +#[derive(Deserr, Debug, Clone, Copy)] #[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)] pub struct ListApiKeys { #[deserr(default, error = DeserrQueryParamError)] diff --git a/meilisearch/src/routes/indexes/documents.rs b/meilisearch/src/routes/indexes/documents.rs index 0ec1057ae..90bf70692 100644 --- a/meilisearch/src/routes/indexes/documents.rs +++ b/meilisearch/src/routes/indexes/documents.rs @@ -4,7 +4,7 @@ use actix_web::http::header::CONTENT_TYPE; use actix_web::web::Data; use actix_web::{web, HttpMessage, HttpRequest, HttpResponse}; use bstr::ByteSlice; -use deserr::DeserializeFromValue; +use deserr::Deserr; use futures::StreamExt; use index_scheduler::IndexScheduler; use log::debug; @@ -80,7 +80,7 @@ pub fn configure(cfg: &mut web::ServiceConfig) { ); } -#[derive(Debug, DeserializeFromValue)] +#[derive(Debug, Deserr)] #[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)] pub struct GetDocument { #[deserr(default, error = DeserrQueryParamError)] @@ -125,7 +125,7 @@ pub async fn delete_document( Ok(HttpResponse::Accepted().json(task)) } -#[derive(Debug, DeserializeFromValue)] +#[derive(Debug, Deserr)] #[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)] pub struct BrowseQuery { #[deserr(default, error = DeserrQueryParamError)] @@ -155,7 +155,7 @@ pub async fn get_all_documents( Ok(HttpResponse::Ok().json(ret)) } -#[derive(Deserialize, Debug, DeserializeFromValue)] +#[derive(Deserialize, Debug, Deserr)] #[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)] pub struct UpdateDocumentsQuery { #[deserr(default, error = DeserrJsonError)] diff --git a/meilisearch/src/routes/indexes/mod.rs b/meilisearch/src/routes/indexes/mod.rs index 2d352bfe5..c087fe202 100644 --- a/meilisearch/src/routes/indexes/mod.rs +++ b/meilisearch/src/routes/indexes/mod.rs @@ -2,7 +2,7 @@ use std::convert::Infallible; use actix_web::web::Data; use actix_web::{web, HttpRequest, HttpResponse}; -use deserr::{DeserializeError, DeserializeFromValue, ValuePointerRef}; +use deserr::{DeserializeError, Deserr, ValuePointerRef}; use index_scheduler::IndexScheduler; use log::debug; use meilisearch_types::deserr::error_messages::immutable_field_error; @@ -73,7 +73,7 @@ impl IndexView { } } -#[derive(DeserializeFromValue, Debug, Clone, Copy)] +#[derive(Deserr, Debug, Clone, Copy)] #[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)] pub struct ListIndexes { #[deserr(default, error = DeserrQueryParamError)] @@ -105,7 +105,7 @@ pub async fn list_indexes( Ok(HttpResponse::Ok().json(ret)) } -#[derive(DeserializeFromValue, Debug)] +#[derive(Deserr, Debug)] #[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)] pub struct IndexCreateRequest { #[deserr(error = DeserrJsonError, missing_field_error = DeserrJsonError::missing_index_uid)] @@ -157,7 +157,7 @@ fn deny_immutable_fields_index( } } -#[derive(DeserializeFromValue, Debug)] +#[derive(Deserr, Debug)] #[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields = deny_immutable_fields_index)] pub struct UpdateIndexRequest { #[deserr(default, error = DeserrJsonError)] diff --git a/meilisearch/src/routes/indexes/search.rs b/meilisearch/src/routes/indexes/search.rs index 545c69ec5..50a2ffd74 100644 --- a/meilisearch/src/routes/indexes/search.rs +++ b/meilisearch/src/routes/indexes/search.rs @@ -31,7 +31,7 @@ pub fn configure(cfg: &mut web::ServiceConfig) { ); } -#[derive(Debug, deserr::DeserializeFromValue)] +#[derive(Debug, deserr::Deserr)] #[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)] pub struct SearchQueryGet { #[deserr(default, error = DeserrQueryParamError)] diff --git a/meilisearch/src/routes/swap_indexes.rs b/meilisearch/src/routes/swap_indexes.rs index 4a7802f2e..2070177d9 100644 --- a/meilisearch/src/routes/swap_indexes.rs +++ b/meilisearch/src/routes/swap_indexes.rs @@ -1,6 +1,6 @@ use actix_web::web::Data; use actix_web::{web, HttpRequest, HttpResponse}; -use deserr::DeserializeFromValue; +use deserr::Deserr; use index_scheduler::IndexScheduler; use meilisearch_types::deserr::DeserrJsonError; use meilisearch_types::error::deserr_codes::InvalidSwapIndexes; @@ -21,7 +21,7 @@ pub fn configure(cfg: &mut web::ServiceConfig) { cfg.service(web::resource("").route(web::post().to(SeqHandler(swap_indexes)))); } -#[derive(DeserializeFromValue, Debug, Clone, PartialEq, Eq)] +#[derive(Deserr, Debug, Clone, PartialEq, Eq)] #[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)] pub struct SwapIndexesPayload { #[deserr(error = DeserrJsonError, missing_field_error = DeserrJsonError::missing_swap_indexes)] diff --git a/meilisearch/src/routes/tasks.rs b/meilisearch/src/routes/tasks.rs index b78be7876..f747320b1 100644 --- a/meilisearch/src/routes/tasks.rs +++ b/meilisearch/src/routes/tasks.rs @@ -1,6 +1,6 @@ use actix_web::web::Data; use actix_web::{web, HttpRequest, HttpResponse}; -use deserr::DeserializeFromValue; +use deserr::Deserr; use index_scheduler::{IndexScheduler, Query, TaskId}; use meilisearch_types::deserr::query_params::Param; use meilisearch_types::deserr::DeserrQueryParamError; @@ -162,7 +162,7 @@ impl From
for DetailsView { } } -#[derive(Debug, DeserializeFromValue)] +#[derive(Debug, Deserr)] #[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)] pub struct TasksFilterQuery { #[deserr(default = Param(DEFAULT_LIMIT), error = DeserrQueryParamError)] @@ -181,19 +181,20 @@ pub struct TasksFilterQuery { #[deserr(default, error = DeserrQueryParamError)] pub index_uids: OptionStarOrList, - #[deserr(default, error = DeserrQueryParamError, from(OptionStarOr) = deserialize_date_after -> InvalidTaskDateError)] + #[deserr(default, error = DeserrQueryParamError, try_from(OptionStarOr) = deserialize_date_after -> InvalidTaskDateError)] pub after_enqueued_at: OptionStarOr, - #[deserr(default, error = DeserrQueryParamError, from(OptionStarOr) = deserialize_date_before -> InvalidTaskDateError)] + #[deserr(default, error = DeserrQueryParamError, try_from(OptionStarOr) = deserialize_date_before -> InvalidTaskDateError)] pub before_enqueued_at: OptionStarOr, - #[deserr(default, error = DeserrQueryParamError, from(OptionStarOr) = deserialize_date_after -> InvalidTaskDateError)] + #[deserr(default, error = DeserrQueryParamError, try_from(OptionStarOr) = deserialize_date_after -> InvalidTaskDateError)] pub after_started_at: OptionStarOr, - #[deserr(default, error = DeserrQueryParamError, from(OptionStarOr) = deserialize_date_before -> InvalidTaskDateError)] + #[deserr(default, error = DeserrQueryParamError, try_from(OptionStarOr) = deserialize_date_before -> InvalidTaskDateError)] pub before_started_at: OptionStarOr, - #[deserr(default, error = DeserrQueryParamError, from(OptionStarOr) = deserialize_date_after -> InvalidTaskDateError)] + #[deserr(default, error = DeserrQueryParamError, try_from(OptionStarOr) = deserialize_date_after -> InvalidTaskDateError)] pub after_finished_at: OptionStarOr, - #[deserr(default, error = DeserrQueryParamError, from(OptionStarOr) = deserialize_date_before -> InvalidTaskDateError)] + #[deserr(default, error = DeserrQueryParamError, try_from(OptionStarOr) = deserialize_date_before -> InvalidTaskDateError)] pub before_finished_at: OptionStarOr, } + impl TasksFilterQuery { fn into_query(self) -> Query { Query { @@ -235,7 +236,7 @@ impl TaskDeletionOrCancelationQuery { } } -#[derive(Debug, DeserializeFromValue)] +#[derive(Debug, Deserr)] #[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)] pub struct TaskDeletionOrCancelationQuery { #[deserr(default, error = DeserrQueryParamError)] @@ -249,19 +250,20 @@ pub struct TaskDeletionOrCancelationQuery { #[deserr(default, error = DeserrQueryParamError)] pub index_uids: OptionStarOrList, - #[deserr(default, error = DeserrQueryParamError, from(OptionStarOr) = deserialize_date_after -> InvalidTaskDateError)] + #[deserr(default, error = DeserrQueryParamError, try_from(OptionStarOr) = deserialize_date_after -> InvalidTaskDateError)] pub after_enqueued_at: OptionStarOr, - #[deserr(default, error = DeserrQueryParamError, from(OptionStarOr) = deserialize_date_before -> InvalidTaskDateError)] + #[deserr(default, error = DeserrQueryParamError, try_from(OptionStarOr) = deserialize_date_before -> InvalidTaskDateError)] pub before_enqueued_at: OptionStarOr, - #[deserr(default, error = DeserrQueryParamError, from(OptionStarOr) = deserialize_date_after -> InvalidTaskDateError)] + #[deserr(default, error = DeserrQueryParamError, try_from(OptionStarOr) = deserialize_date_after -> InvalidTaskDateError)] pub after_started_at: OptionStarOr, - #[deserr(default, error = DeserrQueryParamError, from(OptionStarOr) = deserialize_date_before -> InvalidTaskDateError)] + #[deserr(default, error = DeserrQueryParamError, try_from(OptionStarOr) = deserialize_date_before -> InvalidTaskDateError)] pub before_started_at: OptionStarOr, - #[deserr(default, error = DeserrQueryParamError, from(OptionStarOr) = deserialize_date_after -> InvalidTaskDateError)] + #[deserr(default, error = DeserrQueryParamError, try_from(OptionStarOr) = deserialize_date_after -> InvalidTaskDateError)] pub after_finished_at: OptionStarOr, - #[deserr(default, error = DeserrQueryParamError, from(OptionStarOr) = deserialize_date_before -> InvalidTaskDateError)] + #[deserr(default, error = DeserrQueryParamError, try_from(OptionStarOr) = deserialize_date_before -> InvalidTaskDateError)] pub before_finished_at: OptionStarOr, } + impl TaskDeletionOrCancelationQuery { fn into_query(self) -> Query { Query { @@ -498,7 +500,7 @@ pub fn deserialize_date_before( #[cfg(test)] mod tests { - use deserr::DeserializeFromValue; + use deserr::Deserr; use meili_snap::snapshot; use meilisearch_types::deserr::DeserrQueryParamError; use meilisearch_types::error::{Code, ResponseError}; @@ -507,7 +509,7 @@ mod tests { fn deserr_query_params(j: &str) -> Result where - T: DeserializeFromValue, + T: Deserr, { let value = serde_urlencoded::from_str::(j) .map_err(|e| ResponseError::from_msg(e.to_string(), Code::BadRequest))?; diff --git a/meilisearch/src/search.rs b/meilisearch/src/search.rs index d4a65cc39..f48563141 100644 --- a/meilisearch/src/search.rs +++ b/meilisearch/src/search.rs @@ -3,7 +3,7 @@ use std::collections::{BTreeMap, BTreeSet, HashSet}; use std::str::FromStr; use std::time::Instant; -use deserr::DeserializeFromValue; +use deserr::Deserr; use either::Either; use meilisearch_types::deserr::DeserrJsonError; use meilisearch_types::error::deserr_codes::*; @@ -29,7 +29,7 @@ pub const DEFAULT_CROP_MARKER: fn() -> String = || "…".to_string(); pub const DEFAULT_HIGHLIGHT_PRE_TAG: fn() -> String = || "".to_string(); pub const DEFAULT_HIGHLIGHT_POST_TAG: fn() -> String = || "".to_string(); -#[derive(Debug, Clone, Default, PartialEq, Eq, DeserializeFromValue)] +#[derive(Debug, Clone, Default, PartialEq, Eq, Deserr)] #[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)] pub struct SearchQuery { #[deserr(default, error = DeserrJsonError)] @@ -74,7 +74,7 @@ impl SearchQuery { } } -#[derive(Debug, Clone, PartialEq, Eq, DeserializeFromValue)] +#[derive(Debug, Clone, PartialEq, Eq, Deserr)] #[deserr(rename_all = camelCase)] pub enum MatchingStrategy { /// Remove query words from last to first diff --git a/milli/Cargo.toml b/milli/Cargo.toml index d9458ca70..70658d81d 100644 --- a/milli/Cargo.toml +++ b/milli/Cargo.toml @@ -12,7 +12,7 @@ byteorder = "1.4.3" charabia = { version = "0.7.0", default-features = false } concat-arrays = "0.1.2" crossbeam-channel = "0.5.6" -deserr = "0.3.0" +deserr = "0.4.0" either = "1.8.0" flatten-serde-json = { path = "../flatten-serde-json" } fst = "0.4.7" diff --git a/milli/src/update/settings.rs b/milli/src/update/settings.rs index 1646ab5b2..4f4fa25d6 100644 --- a/milli/src/update/settings.rs +++ b/milli/src/update/settings.rs @@ -2,7 +2,7 @@ use std::collections::{BTreeSet, HashMap, HashSet}; use std::result::Result as StdResult; use charabia::{Tokenizer, TokenizerBuilder}; -use deserr::{DeserializeError, DeserializeFromValue}; +use deserr::{DeserializeError, Deserr}; use itertools::Itertools; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use time::OffsetDateTime; @@ -23,9 +23,9 @@ pub enum Setting { NotSet, } -impl DeserializeFromValue for Setting +impl Deserr for Setting where - T: DeserializeFromValue, + T: Deserr, E: DeserializeError, { fn deserialize_from_value(