From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- third_party/rust/sync15/src/engine/request.rs | 113 ++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 third_party/rust/sync15/src/engine/request.rs (limited to 'third_party/rust/sync15/src/engine/request.rs') diff --git a/third_party/rust/sync15/src/engine/request.rs b/third_party/rust/sync15/src/engine/request.rs new file mode 100644 index 0000000000..d8e20103a8 --- /dev/null +++ b/third_party/rust/sync15/src/engine/request.rs @@ -0,0 +1,113 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use crate::{Guid, ServerTimestamp}; +use std::borrow::Cow; +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct CollectionRequest { + pub collection: Cow<'static, str>, + pub full: bool, + pub ids: Option>, + pub limit: usize, + pub older: Option, + pub newer: Option, + pub order: Option, + pub commit: bool, + pub batch: Option, +} + +impl CollectionRequest { + #[inline] + pub fn new(collection: S) -> CollectionRequest + where + S: Into>, + { + CollectionRequest { + collection: collection.into(), + full: false, + ids: None, + limit: 0, + older: None, + newer: None, + order: None, + commit: false, + batch: None, + } + } + + #[inline] + pub fn ids(mut self, v: V) -> CollectionRequest + where + V: IntoIterator, + V::Item: Into, + { + self.ids = Some(v.into_iter().map(|id| id.into()).collect()); + self + } + + #[inline] + pub fn full(mut self) -> CollectionRequest { + self.full = true; + self + } + + #[inline] + pub fn older_than(mut self, ts: ServerTimestamp) -> CollectionRequest { + self.older = Some(ts); + self + } + + #[inline] + pub fn newer_than(mut self, ts: ServerTimestamp) -> CollectionRequest { + self.newer = Some(ts); + self + } + + #[inline] + pub fn sort_by(mut self, order: RequestOrder) -> CollectionRequest { + self.order = Some(order); + self + } + + #[inline] + pub fn limit(mut self, num: usize) -> CollectionRequest { + self.limit = num; + self + } + + #[inline] + pub fn batch(mut self, batch: Option) -> CollectionRequest { + self.batch = batch; + self + } + + #[inline] + pub fn commit(mut self, v: bool) -> CollectionRequest { + self.commit = v; + self + } +} + +#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] +pub enum RequestOrder { + Oldest, + Newest, + Index, +} + +impl RequestOrder { + #[inline] + pub fn as_str(self) -> &'static str { + match self { + RequestOrder::Oldest => "oldest", + RequestOrder::Newest => "newest", + RequestOrder::Index => "index", + } + } +} + +impl std::fmt::Display for RequestOrder { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(self.as_str()) + } +} -- cgit v1.2.3