use std::{borrow::Cow, cmp::Eq, collections::HashSet as StdHashSet, hash::Hash}; use hashbrown::HashSet; use crate::{ parser::types::Field, registry, resolver_utils::resolve_list, ContextSelectionSet, InputType, InputValueError, InputValueResult, OutputType, Positioned, Result, ServerResult, Value, }; impl InputType for HashSet { type RawValueType = Self; fn type_name() -> Cow<'static, str> { as InputType>::type_name() } fn qualified_type_name() -> String { as InputType>::qualified_type_name() } fn create_type_info(registry: &mut registry::Registry) -> String { as InputType>::create_type_info(registry) } fn parse(value: Option) -> InputValueResult { match value.unwrap_or_default() { Value::List(values) => values .into_iter() .map(|value| InputType::parse(Some(value))) .collect::>() .map_err(InputValueError::propagate), value => Ok({ let mut result = Self::default(); result.insert(InputType::parse(Some(value)).map_err(InputValueError::propagate)?); result }), } } fn to_value(&self) -> Value { Value::List(self.iter().map(InputType::to_value).collect()) } fn as_raw_value(&self) -> Option<&Self::RawValueType> { Some(self) } } #[async_trait::async_trait] impl OutputType for HashSet { fn type_name() -> Cow<'static, str> { as OutputType>::type_name() } fn qualified_type_name() -> String { as OutputType>::qualified_type_name() } fn create_type_info(registry: &mut registry::Registry) -> String { as OutputType>::create_type_info(registry) } async fn resolve( &self, ctx: &ContextSelectionSet<'_>, field: &Positioned, ) -> ServerResult { resolve_list(ctx, field, self, Some(self.len())).await } }