#[cfg(feature = "array-tuples")]
use super::{
one_or_many::{EmptyListError, OneOrMany},
zero_one_or_many::ZeroOneOrMany,
};
#[cfg(feature = "array-tuples")]
pub auto trait NotString {}
#[cfg(feature = "array-tuples")]
impl !NotString for String {}
#[cfg(feature = "array-tuples")]
pub trait ArrayTupleObjectExtStringString: Sized {
type Error;
fn from_hashmap<K, V>(map: ::hashbrown::HashMap<K, V>) -> Result<Self, Self::Error>
where
K: Into<String>,
V: Into<String>;
fn from_array_tuple<K, V, F>(f: F) -> Result<Self, Self::Error>
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<String>,
V: Into<String>,
{
Self::from_hashmap(f())
}
}
#[cfg(feature = "array-tuples")]
pub trait ArrayTupleObjectExtStringV<V1: NotString>: Sized {
type Error;
fn from_hashmap<K, V>(map: ::hashbrown::HashMap<K, V>) -> Result<Self, Self::Error>
where
K: Into<String>,
V: Into<V1>;
fn from_array_tuple<K, V, F>(f: F) -> Result<Self, Self::Error>
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<String>,
V: Into<V1>,
{
Self::from_hashmap(f())
}
}
#[cfg(feature = "array-tuples")]
pub trait ArrayTupleObjectExtKString<K1: NotString>: Sized {
type Error;
fn from_hashmap<K, V>(map: ::hashbrown::HashMap<K, V>) -> Result<Self, Self::Error>
where
K: Into<K1>,
V: Into<String>;
fn from_array_tuple<K, V, F>(f: F) -> Result<Self, Self::Error>
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<K1>,
V: Into<String>,
{
Self::from_hashmap(f())
}
}
#[cfg(feature = "array-tuples")]
pub trait ArrayTupleObjectExtKV<K1: NotString, V1: NotString>: Sized {
type Error;
fn from_hashmap<K, V>(map: ::hashbrown::HashMap<K, V>) -> Result<Self, Self::Error>
where
K: Into<K1>,
V: Into<V1>;
fn from_array_tuple<K, V, F>(f: F) -> Result<Self, Self::Error>
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<K1>,
V: Into<V1>,
{
Self::from_hashmap(f())
}
}
#[cfg(feature = "array-tuples")]
impl ArrayTupleObjectExtStringString for Vec<(String, String)> {
type Error = std::convert::Infallible;
fn from_hashmap<K, V>(map: ::hashbrown::HashMap<K, V>) -> Result<Self, Self::Error>
where
K: Into<String>,
V: Into<String>,
{
Ok(map.into_iter().map(|(k, v)| (k.into(), v.into())).collect())
}
}
#[cfg(feature = "array-tuples")]
impl<V1: NotString> ArrayTupleObjectExtStringV<V1> for Vec<(String, V1)> {
type Error = std::convert::Infallible;
fn from_hashmap<K, V>(map: ::hashbrown::HashMap<K, V>) -> Result<Self, Self::Error>
where
K: Into<String>,
V: Into<V1>,
{
Ok(map.into_iter().map(|(k, v)| (k.into(), v.into())).collect())
}
}
#[cfg(feature = "array-tuples")]
impl<K1: NotString> ArrayTupleObjectExtKString<K1> for Vec<(K1, String)> {
type Error = std::convert::Infallible;
fn from_hashmap<K, V>(map: ::hashbrown::HashMap<K, V>) -> Result<Self, Self::Error>
where
K: Into<K1>,
V: Into<String>,
{
Ok(map.into_iter().map(|(k, v)| (k.into(), v.into())).collect())
}
}
#[cfg(feature = "array-tuples")]
impl<K1: NotString, V1: NotString> ArrayTupleObjectExtKV<K1, V1> for Vec<(K1, V1)> {
type Error = std::convert::Infallible;
fn from_hashmap<K, V>(map: ::hashbrown::HashMap<K, V>) -> Result<Self, Self::Error>
where
K: Into<K1>,
V: Into<V1>,
{
Ok(map.into_iter().map(|(k, v)| (k.into(), v.into())).collect())
}
}
#[cfg(feature = "array-tuples")]
impl ArrayTupleObjectExtStringString for Option<Vec<(String, String)>> {
type Error = std::convert::Infallible;
fn from_hashmap<K, V>(map: ::hashbrown::HashMap<K, V>) -> Result<Self, Self::Error>
where
K: Into<String>,
V: Into<String>,
{
let items: Vec<(String, String)> =
map.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
Ok(if items.is_empty() { None } else { Some(items) })
}
}
#[cfg(feature = "array-tuples")]
impl<V1: NotString> ArrayTupleObjectExtStringV<V1> for Option<Vec<(String, V1)>> {
type Error = std::convert::Infallible;
fn from_hashmap<K, V>(map: ::hashbrown::HashMap<K, V>) -> Result<Self, Self::Error>
where
K: Into<String>,
V: Into<V1>,
{
let items: Vec<(String, V1)> = map.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
Ok(if items.is_empty() { None } else { Some(items) })
}
}
#[cfg(feature = "array-tuples")]
impl<K1: NotString> ArrayTupleObjectExtKString<K1> for Option<Vec<(K1, String)>> {
type Error = std::convert::Infallible;
fn from_hashmap<K, V>(map: ::hashbrown::HashMap<K, V>) -> Result<Self, Self::Error>
where
K: Into<K1>,
V: Into<String>,
{
let items: Vec<(K1, String)> = map.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
Ok(if items.is_empty() { None } else { Some(items) })
}
}
#[cfg(feature = "array-tuples")]
impl<K1: NotString, V1: NotString> ArrayTupleObjectExtKV<K1, V1> for Option<Vec<(K1, V1)>> {
type Error = std::convert::Infallible;
fn from_hashmap<K, V>(map: ::hashbrown::HashMap<K, V>) -> Result<Self, Self::Error>
where
K: Into<K1>,
V: Into<V1>,
{
let items: Vec<(K1, V1)> = map.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
Ok(if items.is_empty() { None } else { Some(items) })
}
}
#[cfg(feature = "array-tuples")]
pub trait CollectionArrayTupleExtStringString {
fn json<K, V, F>(f: F) -> Self
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<String>,
V: Into<String>;
}
#[cfg(feature = "array-tuples")]
pub trait CollectionArrayTupleExtStringV<V1: NotString> {
fn json<K, V, F>(f: F) -> Self
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<String>,
V: Into<V1>;
}
#[cfg(feature = "array-tuples")]
pub trait CollectionArrayTupleExtKString<K1: NotString> {
fn json<K, V, F>(f: F) -> Self
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<K1>,
V: Into<String>;
}
#[cfg(feature = "array-tuples")]
pub trait CollectionArrayTupleExtKV<K1: NotString, V1: NotString> {
fn json<K, V, F>(f: F) -> Self
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<K1>,
V: Into<V1>;
}
#[cfg(feature = "array-tuples")]
pub trait TryCollectionArrayTupleExtStringString {
type Error;
fn try_json<K, V, F>(f: F) -> Result<Self, Self::Error>
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<String>,
V: Into<String>,
Self: Sized;
}
#[cfg(feature = "array-tuples")]
pub trait TryCollectionArrayTupleExtStringV<V1: NotString> {
type Error;
fn try_json<K, V, F>(f: F) -> Result<Self, Self::Error>
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<String>,
V: Into<V1>,
Self: Sized;
}
#[cfg(feature = "array-tuples")]
pub trait TryCollectionArrayTupleExtKString<K1: NotString> {
type Error;
fn try_json<K, V, F>(f: F) -> Result<Self, Self::Error>
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<K1>,
V: Into<String>,
Self: Sized;
}
#[cfg(feature = "array-tuples")]
pub trait TryCollectionArrayTupleExtKV<K1: NotString, V1: NotString> {
type Error;
fn try_json<K, V, F>(f: F) -> Result<Self, Self::Error>
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<K1>,
V: Into<V1>,
Self: Sized;
}
#[cfg(feature = "array-tuples")]
impl TryCollectionArrayTupleExtStringString for OneOrMany<(String, String)> {
type Error = EmptyListError;
fn try_json<K, V, F>(f: F) -> Result<Self, Self::Error>
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<String>,
V: Into<String>,
{
let map = f();
let items: Vec<(String, String)> =
map.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
OneOrMany::many(items)
}
}
#[cfg(feature = "array-tuples")]
impl<V1> TryCollectionArrayTupleExtStringV<V1> for OneOrMany<(String, V1)>
where
V1: NotString,
{
type Error = EmptyListError;
fn try_json<K, V, F>(f: F) -> Result<Self, Self::Error>
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<String>,
V: Into<V1>,
{
let map = f();
let items: Vec<(String, V1)> = map.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
OneOrMany::many(items)
}
}
#[cfg(feature = "array-tuples")]
impl<K1> TryCollectionArrayTupleExtKString<K1> for OneOrMany<(K1, String)>
where
K1: NotString,
{
type Error = EmptyListError;
fn try_json<K, V, F>(f: F) -> Result<Self, Self::Error>
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<K1>,
V: Into<String>,
{
let map = f();
let items: Vec<(K1, String)> = map.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
OneOrMany::many(items)
}
}
#[cfg(feature = "array-tuples")]
impl<K1, V1> TryCollectionArrayTupleExtKV<K1, V1> for OneOrMany<(K1, V1)>
where
K1: NotString,
V1: NotString,
{
type Error = EmptyListError;
fn try_json<K, V, F>(f: F) -> Result<Self, Self::Error>
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<K1>,
V: Into<V1>,
{
let map = f();
let items: Vec<(K1, V1)> = map.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
OneOrMany::many(items)
}
}
#[cfg(feature = "array-tuples")]
impl CollectionArrayTupleExtStringString for Vec<(String, String)> {
fn json<K, V, F>(f: F) -> Self
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<String>,
V: Into<String>,
{
f().into_iter().map(|(k, v)| (k.into(), v.into())).collect()
}
}
#[cfg(feature = "array-tuples")]
impl<V1> CollectionArrayTupleExtStringV<V1> for Vec<(String, V1)>
where
V1: NotString,
{
fn json<K, V, F>(f: F) -> Self
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<String>,
V: Into<V1>,
{
f().into_iter().map(|(k, v)| (k.into(), v.into())).collect()
}
}
#[cfg(feature = "array-tuples")]
impl<K1> CollectionArrayTupleExtKString<K1> for Vec<(K1, String)>
where
K1: NotString,
{
fn json<K, V, F>(f: F) -> Self
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<K1>,
V: Into<String>,
{
f().into_iter().map(|(k, v)| (k.into(), v.into())).collect()
}
}
#[cfg(feature = "array-tuples")]
impl<K1, V1> CollectionArrayTupleExtKV<K1, V1> for Vec<(K1, V1)>
where
K1: NotString,
V1: NotString,
{
fn json<K, V, F>(f: F) -> Self
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<K1>,
V: Into<V1>,
{
f().into_iter().map(|(k, v)| (k.into(), v.into())).collect()
}
}
#[cfg(feature = "array-tuples")]
impl CollectionArrayTupleExtStringString for ZeroOneOrMany<(String, String)> {
fn json<K, V, F>(f: F) -> Self
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<String>,
V: Into<String>,
{
let map = f();
let items: Vec<(String, String)> =
map.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
ZeroOneOrMany::many(items)
}
}
#[cfg(feature = "array-tuples")]
impl<V1> CollectionArrayTupleExtStringV<V1> for ZeroOneOrMany<(String, V1)>
where
V1: NotString,
{
fn json<K, V, F>(f: F) -> Self
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<String>,
V: Into<V1>,
{
let map = f();
let items: Vec<(String, V1)> = map.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
ZeroOneOrMany::many(items)
}
}
#[cfg(feature = "array-tuples")]
impl<K1> CollectionArrayTupleExtKString<K1> for ZeroOneOrMany<(K1, String)>
where
K1: NotString,
{
fn json<K, V, F>(f: F) -> Self
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<K1>,
V: Into<String>,
{
let map = f();
let items: Vec<(K1, String)> = map.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
ZeroOneOrMany::many(items)
}
}
#[cfg(feature = "array-tuples")]
impl<K1, V1> CollectionArrayTupleExtKV<K1, V1> for ZeroOneOrMany<(K1, V1)>
where
K1: NotString,
V1: NotString,
{
fn json<K, V, F>(f: F) -> Self
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<K1>,
V: Into<V1>,
{
let map = f();
let items: Vec<(K1, V1)> = map.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
ZeroOneOrMany::many(items)
}
}
#[cfg(feature = "array-tuples")]
impl TryCollectionArrayTupleExtStringString for ZeroOneOrMany<(String, String)> {
type Error = std::convert::Infallible;
fn try_json<K, V, F>(f: F) -> Result<Self, Self::Error>
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<String>,
V: Into<String>,
{
let map = f();
let items: Vec<(String, String)> =
map.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
Ok(ZeroOneOrMany::many(items))
}
}
#[cfg(feature = "array-tuples")]
impl<V1> TryCollectionArrayTupleExtStringV<V1> for ZeroOneOrMany<(String, V1)>
where
V1: NotString,
{
type Error = std::convert::Infallible;
fn try_json<K, V, F>(f: F) -> Result<Self, Self::Error>
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<String>,
V: Into<V1>,
{
let map = f();
let items: Vec<(String, V1)> = map.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
Ok(ZeroOneOrMany::many(items))
}
}
#[cfg(feature = "array-tuples")]
impl<K1> TryCollectionArrayTupleExtKString<K1> for ZeroOneOrMany<(K1, String)>
where
K1: NotString,
{
type Error = std::convert::Infallible;
fn try_json<K, V, F>(f: F) -> Result<Self, Self::Error>
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<K1>,
V: Into<String>,
{
let map = f();
let items: Vec<(K1, String)> = map.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
Ok(ZeroOneOrMany::many(items))
}
}
#[cfg(feature = "array-tuples")]
impl<K1, V1> TryCollectionArrayTupleExtKV<K1, V1> for ZeroOneOrMany<(K1, V1)>
where
K1: NotString,
V1: NotString,
{
type Error = std::convert::Infallible;
fn try_json<K, V, F>(f: F) -> Result<Self, Self::Error>
where
F: FnOnce() -> ::hashbrown::HashMap<K, V>,
K: Into<K1>,
V: Into<V1>,
{
let map = f();
let items: Vec<(K1, V1)> = map.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
Ok(ZeroOneOrMany::many(items))
}
}