Import upstream v0.16.22, stripped
Upstream commit: 474dd0229cb20cf513036619781ed97bd8073c3f Enterprise-only files removed or emptied: 63 Enterprise-only snippets removed: 117 in 50 files Dangling module declarations removed: 5 Cargo edits turning enterprise off: 14 Verification: clean Enterprise feature gates left for rebuilt features: 19 in 18 files Produced by tools/fork/strip.py. The full report is in docs/fork/strip-reports/ on main.
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use ahash::AHashMap;
|
||||
use jmap_tools::Property;
|
||||
use serde::{
|
||||
Deserialize, Deserializer, Serialize, Serializer,
|
||||
de::{self, MapAccess, Visitor},
|
||||
};
|
||||
use std::{borrow::Cow, fmt, str::FromStr};
|
||||
|
||||
pub mod availability;
|
||||
pub mod changes;
|
||||
pub mod copy;
|
||||
pub mod get;
|
||||
pub mod import;
|
||||
pub mod lookup;
|
||||
pub mod parse;
|
||||
pub mod query;
|
||||
pub mod query_changes;
|
||||
pub mod search_snippet;
|
||||
pub mod set;
|
||||
pub mod upload;
|
||||
pub mod validate;
|
||||
|
||||
#[inline(always)]
|
||||
fn ahash_is_empty<K, V>(map: &AHashMap<K, V>) -> bool {
|
||||
map.is_empty()
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[repr(transparent)]
|
||||
pub struct PropertyWrapper<T: Property>(pub T);
|
||||
|
||||
impl<T: Property> From<T> for PropertyWrapper<T> {
|
||||
fn from(value: T) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Property> Serialize for PropertyWrapper<T> {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str(self.0.to_cow().as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct JmapDict<T: FromStr>(pub Vec<T>);
|
||||
|
||||
struct JmapDictVisitor<'de, T: FromStr> {
|
||||
marker: std::marker::PhantomData<&'de T>,
|
||||
}
|
||||
|
||||
impl<'de, T: FromStr> Visitor<'de> for JmapDictVisitor<'de, T> {
|
||||
type Value = JmapDict<T>;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("a map")
|
||||
}
|
||||
|
||||
fn visit_map<M>(self, mut access: M) -> Result<Self::Value, M::Error>
|
||||
where
|
||||
M: MapAccess<'de>,
|
||||
{
|
||||
let mut vec = Vec::with_capacity(3);
|
||||
|
||||
while let Some(key) = access.next_key::<Cow<'de, str>>()? {
|
||||
let key = T::from_str(&key).map_err(|_| de::Error::custom("invalid dictionary key"))?;
|
||||
if access.next_value::<Option<bool>>()?.unwrap_or(false) {
|
||||
vec.push(key);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(JmapDict(vec))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, T: FromStr + 'static> Deserialize<'de> for JmapDict<T> {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
deserializer.deserialize_map(JmapDictVisitor {
|
||||
marker: std::marker::PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user