From d8bbc7858622b6d9c278469aab701ca0b609cddf Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:35:49 +0200 Subject: Merging upstream version 126.0. Signed-off-by: Daniel Baumann --- third_party/rust/remote_settings/src/client.rs | 54 ++++++++++++++------------ 1 file changed, 29 insertions(+), 25 deletions(-) (limited to 'third_party/rust/remote_settings/src/client.rs') diff --git a/third_party/rust/remote_settings/src/client.rs b/third_party/rust/remote_settings/src/client.rs index 0d99de9cc1..2cf26b7319 100644 --- a/third_party/rust/remote_settings/src/client.rs +++ b/third_party/rust/remote_settings/src/client.rs @@ -64,7 +64,7 @@ impl Client { /// collection defined by the [ClientConfig] used to generate this [Client]. pub fn get_records_since(&self, timestamp: u64) -> Result { self.get_records_with_options( - GetItemsOptions::new().gt("last_modified", timestamp.to_string()), + GetItemsOptions::new().filter_gt("last_modified", timestamp.to_string()), ) } @@ -307,7 +307,7 @@ struct AttachmentsCapability { } /// Options for requests to endpoints that return multiple items. -#[derive(Clone, Debug, Default)] +#[derive(Clone, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)] pub struct GetItemsOptions { filters: Vec, sort: Vec, @@ -328,14 +328,14 @@ impl GetItemsOptions { /// `author.name`. `value` can be a bare number or string (like /// `2` or `Ben`), or a stringified JSON value (`"2.0"`, `[1, 2]`, /// `{"checked": true}`). - pub fn eq(&mut self, field: impl Into, value: impl Into) -> &mut Self { + pub fn filter_eq(&mut self, field: impl Into, value: impl Into) -> &mut Self { self.filters.push(Filter::Eq(field.into(), value.into())); self } /// Sets an option to only return items whose `field` is not equal to the /// given `value`. - pub fn not(&mut self, field: impl Into, value: impl Into) -> &mut Self { + pub fn filter_not(&mut self, field: impl Into, value: impl Into) -> &mut Self { self.filters.push(Filter::Not(field.into(), value.into())); self } @@ -343,7 +343,11 @@ impl GetItemsOptions { /// Sets an option to only return items whose `field` is an array that /// contains the given `value`. If `value` is a stringified JSON array, the /// field must contain all its elements. - pub fn contains(&mut self, field: impl Into, value: impl Into) -> &mut Self { + pub fn filter_contains( + &mut self, + field: impl Into, + value: impl Into, + ) -> &mut Self { self.filters .push(Filter::Contains(field.into(), value.into())); self @@ -351,47 +355,47 @@ impl GetItemsOptions { /// Sets an option to only return items whose `field` is strictly less /// than the given `value`. - pub fn lt(&mut self, field: impl Into, value: impl Into) -> &mut Self { + pub fn filter_lt(&mut self, field: impl Into, value: impl Into) -> &mut Self { self.filters.push(Filter::Lt(field.into(), value.into())); self } /// Sets an option to only return items whose `field` is strictly greater /// than the given `value`. - pub fn gt(&mut self, field: impl Into, value: impl Into) -> &mut Self { + pub fn filter_gt(&mut self, field: impl Into, value: impl Into) -> &mut Self { self.filters.push(Filter::Gt(field.into(), value.into())); self } /// Sets an option to only return items whose `field` is less than or equal /// to the given `value`. - pub fn max(&mut self, field: impl Into, value: impl Into) -> &mut Self { + pub fn filter_max(&mut self, field: impl Into, value: impl Into) -> &mut Self { self.filters.push(Filter::Max(field.into(), value.into())); self } /// Sets an option to only return items whose `field` is greater than or /// equal to the given `value`. - pub fn min(&mut self, field: impl Into, value: impl Into) -> &mut Self { + pub fn filter_min(&mut self, field: impl Into, value: impl Into) -> &mut Self { self.filters.push(Filter::Min(field.into(), value.into())); self } /// Sets an option to only return items whose `field` is a string that /// contains the substring `value`. `value` can contain `*` wildcards. - pub fn like(&mut self, field: impl Into, value: impl Into) -> &mut Self { + pub fn filter_like(&mut self, field: impl Into, value: impl Into) -> &mut Self { self.filters.push(Filter::Like(field.into(), value.into())); self } /// Sets an option to only return items that have the given `field`. - pub fn has(&mut self, field: impl Into) -> &mut Self { + pub fn filter_has(&mut self, field: impl Into) -> &mut Self { self.filters.push(Filter::Has(field.into())); self } /// Sets an option to only return items that do not have the given `field`. - pub fn has_not(&mut self, field: impl Into) -> &mut Self { + pub fn filter_has_not(&mut self, field: impl Into) -> &mut Self { self.filters.push(Filter::HasNot(field.into())); self } @@ -454,7 +458,7 @@ impl GetItemsOptions { } /// The order in which to return items. -#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] pub enum SortOrder { /// Smaller values first. Ascending, @@ -462,7 +466,7 @@ pub enum SortOrder { Descending, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] enum Filter { Eq(String, String), Not(String, String), @@ -495,7 +499,7 @@ impl Filter { } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] struct Sort(String, SortOrder); impl Sort { @@ -692,16 +696,16 @@ mod test { .field("a") .field("c") .field("b") - .eq("a", "b") - .lt("c.d", "5") - .gt("e", "15") - .max("f", "20") - .min("g", "10") - .not("h", "i") - .like("j", "*k*") - .has("l") - .has_not("m") - .contains("n", "o") + .filter_eq("a", "b") + .filter_lt("c.d", "5") + .filter_gt("e", "15") + .filter_max("f", "20") + .filter_min("g", "10") + .filter_not("h", "i") + .filter_like("j", "*k*") + .filter_has("l") + .filter_has_not("m") + .filter_contains("n", "o") .sort("b", SortOrder::Descending) .sort("a", SortOrder::Ascending) .limit(3); -- cgit v1.2.3