Re-impl renewed traits machinery for container types

This commit is contained in:
tyranron 2022-06-09 16:16:30 +02:00
parent 5ab398e22b
commit be010e8123
No known key found for this signature in database
GPG key ID: 762E144FB230A4F0
9 changed files with 164 additions and 132 deletions

View file

@ -1369,12 +1369,13 @@ impl<'r, S: 'r> Registry<'r, S> {
/// [`graphql::Type`].
///
/// [`graphql::Type`]: resolve::Type
pub fn build_nullable_type_new<T, Info>(&mut self, info: &Info) -> NullableMeta<'r>
pub fn build_nullable_type_reworked<T, BH, TI>(&mut self, type_info: &TI) -> NullableMeta<'r>
where
T: resolve::Type<Info, S> + ?Sized,
Info: ?Sized,
T: resolve::Type<TI, S, BH> + ?Sized,
BH: ?Sized,
TI: ?Sized,
{
NullableMeta::new(T::meta(self, info).as_type())
NullableMeta::new(T::meta(self, type_info).as_type())
}
/// Creates an [`ObjectMeta`] type with the given `fields`.

View file

@ -162,7 +162,7 @@ pub trait InputValue<'input, ScalarValue: 'input, Behavior: ?Sized = behavior::S
) -> Result<Self, Self::Error>;
fn try_from_implicit_null() -> Result<Self, Self::Error> {
Self::try_from_input_value(&graphql::InputValue::<ScalarValue>::Null)
Self::try_from_input_value(&graphql::InputValue::Null)
}
}
@ -182,7 +182,7 @@ pub trait InputValueAs<'input, Wrapper, ScalarValue: 'input, Behavior: ?Sized =
) -> Result<Wrapper, Self::Error>;
fn try_from_implicit_null() -> Result<Wrapper, Self::Error> {
Self::try_from_input_value(&graphql::InputValue::<ScalarValue>::Null)
Self::try_from_input_value(&graphql::InputValue::Null)
}
}
@ -195,7 +195,7 @@ pub trait InputValueAsRef<ScalarValue, Behavior: ?Sized = behavior::Standard> {
where
ScalarValue: 'a,
{
Self::try_from_input_value(&graphql::InputValue::<ScalarValue>::Null)
Self::try_from_input_value(&graphql::InputValue::Null)
}
}

View file

@ -15,11 +15,11 @@ where
TI: ?Sized,
BH: ?Sized,
{
fn meta<'r>(registry: &mut Registry<'r, SV>, info: &TI) -> MetaType<'r, SV>
fn meta<'r>(registry: &mut Registry<'r, SV>, type_info: &TI) -> MetaType<'r, SV>
where
SV: 'r,
{
T::meta(registry, info)
T::meta(registry, type_info)
}
}
@ -29,8 +29,8 @@ where
TI: ?Sized,
BH: ?Sized,
{
fn type_name(info: &TI) -> &str {
T::type_name(info)
fn type_name(type_info: &TI) -> &str {
T::type_name(type_info)
}
}
@ -40,8 +40,8 @@ where
TI: ?Sized,
BH: ?Sized,
{
fn concrete_type_name<'i>(&self, info: &'i TI) -> &'i str {
(**self).concrete_type_name(info)
fn concrete_type_name<'i>(&self, type_info: &'i TI) -> &'i str {
(**self).concrete_type_name(type_info)
}
}

View file

@ -13,11 +13,11 @@ where
TI: ?Sized,
BH: ?Sized,
{
fn meta<'r>(registry: &mut Registry<'r, SV>, info: &TI) -> MetaType<'r, SV>
fn meta<'r>(registry: &mut Registry<'r, SV>, type_info: &TI) -> MetaType<'r, SV>
where
SV: 'r,
{
T::meta(registry, info)
T::meta(registry, type_info)
}
}
@ -27,8 +27,8 @@ where
TI: ?Sized,
BH: ?Sized,
{
fn type_name(info: &TI) -> &str {
T::type_name(info)
fn type_name(type_info: &TI) -> &str {
T::type_name(type_info)
}
}
@ -38,8 +38,8 @@ where
TI: ?Sized,
BH: ?Sized,
{
fn concrete_type_name<'i>(&self, info: &'i TI) -> &'i str {
(**self).concrete_type_name(info)
fn concrete_type_name<'i>(&self, type_info: &'i TI) -> &'i str {
(**self).concrete_type_name(type_info)
}
}

View file

@ -272,82 +272,89 @@ impl<T: Clone> Nullable<&mut T> {
}
}
/*
impl<T, Info, S> resolve::Type<Info, S> for Nullable<T>
impl<T, TI, SV, BH> resolve::Type<TI, SV, BH> for Nullable<T>
where
T: resolve::Type<Info, S>,
Info: ?Sized,
T: resolve::Type<TI, SV, BH>,
TI: ?Sized,
BH: ?Sized,
{
fn meta<'r>(registry: &mut Registry<'r, S>, info: &Info) -> MetaType<'r, S>
fn meta<'r>(registry: &mut Registry<'r, SV>, type_info: &TI) -> MetaType<'r, SV>
where
S: 'r,
SV: 'r,
{
registry.build_nullable_type_new::<T, _>(info).into_meta()
registry
.build_nullable_type_reworked::<T, BH, _>(type_info)
.into_meta()
}
}
impl<T, Info, Ctx, S> resolve::Value<Info, Ctx, S> for Nullable<T>
impl<T, TI, CX, SV, BH> resolve::Value<TI, CX, SV, BH> for Nullable<T>
where
T: resolve::Value<Info, Ctx, S>,
Info: ?Sized,
Ctx: ?Sized,
T: resolve::Value<TI, CX, SV, BH>,
TI: ?Sized,
CX: ?Sized,
BH: ?Sized,
{
fn resolve_value(
&self,
selection_set: Option<&[Selection<'_, S>]>,
info: &Info,
executor: &Executor<Ctx, S>,
) -> ExecutionResult<S> {
selection_set: Option<&[Selection<'_, SV>]>,
type_info: &TI,
executor: &Executor<CX, SV>,
) -> ExecutionResult<SV> {
match self {
Self::Some(v) => v.resolve_value(selection_set, info, executor),
Self::ExplicitNull | Self::ImplicitNull => Ok(graphql::Value::Null),
Self::Some(v) => v.resolve_value(selection_set, type_info, executor),
Self::ImplicitNull | Self::ExplicitNull => Ok(graphql::Value::Null),
}
}
}
impl<T, Info, Ctx, S> resolve::ValueAsync<Info, Ctx, S> for Nullable<T>
impl<T, TI, CX, SV, BH> resolve::ValueAsync<TI, CX, SV, BH> for Nullable<T>
where
T: resolve::ValueAsync<Info, Ctx, S>,
Info: ?Sized,
Ctx: ?Sized,
S: Send,
T: resolve::ValueAsync<TI, CX, SV, BH>,
TI: ?Sized,
CX: ?Sized,
SV: Send,
BH: ?Sized,
{
fn resolve_value_async<'r>(
&'r self,
selection_set: Option<&'r [Selection<'_, S>]>,
info: &'r Info,
executor: &'r Executor<Ctx, S>,
) -> BoxFuture<'r, ExecutionResult<S>> {
selection_set: Option<&'r [Selection<'_, SV>]>,
type_info: &'r TI,
executor: &'r Executor<CX, SV>,
) -> BoxFuture<'r, ExecutionResult<SV>> {
match self {
Self::Some(v) => v.resolve_value_async(selection_set, info, executor),
Self::ExplicitNull | Self::ImplicitNull => Box::pin(future::ok(graphql::Value::Null)),
Self::Some(v) => v.resolve_value_async(selection_set, type_info, executor),
Self::ImplicitNull | Self::ExplicitNull => Box::pin(future::ok(graphql::Value::Null)),
}
}
}
impl<T, S> resolve::ToInputValue<S> for Nullable<T>
impl<T, SV, BH> resolve::ToInputValue<SV, BH> for Nullable<T>
where
T: resolve::ToInputValue<S>,
T: resolve::ToInputValue<SV, BH>,
BH: ?Sized,
{
fn to_input_value(&self) -> graphql::InputValue<S> {
fn to_input_value(&self) -> graphql::InputValue<SV> {
match self {
Self::Some(v) => v.to_input_value(),
Self::ExplicitNull | Self::ImplicitNull => graphql::InputValue::Null,
Self::ImplicitNull | Self::ExplicitNull => graphql::InputValue::Null,
}
}
}
impl<'inp, T, S: 'inp> resolve::InputValue<'inp, S> for Nullable<T>
impl<'i, T, SV, BH> resolve::InputValue<'i, SV, BH> for Nullable<T>
where
T: resolve::InputValue<'inp, S>,
T: resolve::InputValue<'i, SV, BH>,
SV: 'i,
BH: ?Sized,
{
type Error = <T as resolve::InputValue<'inp, S>>::Error;
type Error = T::Error;
fn try_from_input_value(v: &'inp InputValue<S>) -> Result<Self, Self::Error> {
fn try_from_input_value(v: &'i graphql::InputValue<SV>) -> Result<Self, Self::Error> {
if v.is_null() {
Ok(Self::ExplicitNull)
} else {
<T as resolve::InputValue<'inp, S>>::try_from_input_value(v).map(Self::Some)
T::try_from_input_value(v).map(Self::Some)
}
}
@ -356,47 +363,55 @@ where
}
}
impl<'i, T, Info, S: 'i> graphql::InputType<'i, Info, S> for Nullable<T>
impl<'i, T, TI, SV, BH> graphql::InputType<'i, TI, SV, BH> for Nullable<T>
where
T: graphql::InputType<'i, Info, S>,
Info: ?Sized,
T: graphql::InputType<'i, TI, SV, BH>,
TI: ?Sized,
SV: 'i,
BH: ?Sized,
{
fn assert_input_type() {
T::assert_input_type()
}
}
impl<T, S> graphql::OutputType<S> for Nullable<T>
impl<T, TI, CX, SV, BH> graphql::OutputType<TI, CX, SV, BH> for Nullable<T>
where
T: graphql::OutputType<S>,
T: graphql::OutputType<TI, CX, SV, BH>,
TI: ?Sized,
CX: ?Sized,
BH: ?Sized,
Self: resolve::ValueAsync<TI, CX, SV, BH>,
{
fn assert_output_type() {
T::assert_output_type()
}
}
impl<T, S> reflect::BaseType<S> for Nullable<T>
impl<T, BH> reflect::BaseType<BH> for Nullable<T>
where
T: reflect::BaseType<S>,
T: reflect::BaseType<BH>,
BH: ?Sized,
{
const NAME: reflect::Type = T::NAME;
}
impl<T, S> reflect::BaseSubTypes<S> for Nullable<T>
impl<T, BH> reflect::BaseSubTypes<BH> for Nullable<T>
where
T: reflect::BaseSubTypes<S>,
T: reflect::BaseSubTypes<BH>,
BH: ?Sized,
{
const NAMES: reflect::Types = T::NAMES;
}
impl<T, S> reflect::WrappedType<S> for Nullable<T>
impl<T, BH> reflect::WrappedType<BH> for Nullable<T>
where
T: reflect::WrappedType<S>,
T: reflect::WrappedType<BH>,
BH: ?Sized,
{
const VALUE: reflect::WrappedValue = reflect::wrap::nullable(T::VALUE);
}
*/
////////////////////////////////////////////////////////////////////////////////
impl<S, T> GraphQLType<S> for Nullable<T>

View file

@ -8,64 +8,70 @@ use crate::{
schema::meta::MetaType,
BoxFuture, Selection,
};
/*
impl<T, Info, S> resolve::Type<Info, S> for Option<T>
impl<T, TI, SV, BH> resolve::Type<TI, SV, BH> for Option<T>
where
T: resolve::Type<Info, S>,
Info: ?Sized,
T: resolve::Type<TI, SV, BH>,
TI: ?Sized,
BH: ?Sized,
{
fn meta<'r>(registry: &mut Registry<'r, S>, info: &Info) -> MetaType<'r, S>
fn meta<'r>(registry: &mut Registry<'r, SV>, type_info: &TI) -> MetaType<'r, SV>
where
S: 'r,
SV: 'r,
{
registry.build_nullable_type_new::<T, _>(info).into_meta()
registry
.build_nullable_type_reworked::<T, BH, _>(type_info)
.into_meta()
}
}
impl<T, Info, Ctx, S> resolve::Value<Info, Ctx, S> for Option<T>
impl<T, TI, CX, SV, BH> resolve::Value<TI, CX, SV, BH> for Option<T>
where
T: resolve::Value<Info, Ctx, S>,
Info: ?Sized,
Ctx: ?Sized,
T: resolve::Value<TI, CX, SV, BH>,
TI: ?Sized,
CX: ?Sized,
BH: ?Sized,
{
fn resolve_value(
&self,
selection_set: Option<&[Selection<'_, S>]>,
info: &Info,
executor: &Executor<Ctx, S>,
) -> ExecutionResult<S> {
selection_set: Option<&[Selection<'_, SV>]>,
type_info: &TI,
executor: &Executor<CX, SV>,
) -> ExecutionResult<SV> {
match self {
Some(v) => v.resolve_value(selection_set, info, executor),
Some(v) => v.resolve_value(selection_set, type_info, executor),
None => Ok(graphql::Value::Null),
}
}
}
impl<T, Info, Ctx, S> resolve::ValueAsync<Info, Ctx, S> for Option<T>
impl<T, TI, CX, SV, BH> resolve::ValueAsync<TI, CX, SV, BH> for Option<T>
where
T: resolve::ValueAsync<Info, Ctx, S>,
Info: ?Sized,
Ctx: ?Sized,
S: Send,
T: resolve::ValueAsync<TI, CX, SV, BH>,
TI: ?Sized,
CX: ?Sized,
SV: Send,
BH: ?Sized,
{
fn resolve_value_async<'r>(
&'r self,
selection_set: Option<&'r [Selection<'_, S>]>,
info: &'r Info,
executor: &'r Executor<Ctx, S>,
) -> BoxFuture<'r, ExecutionResult<S>> {
selection_set: Option<&'r [Selection<'_, SV>]>,
type_info: &'r TI,
executor: &'r Executor<CX, SV>,
) -> BoxFuture<'r, ExecutionResult<SV>> {
match self {
Some(v) => v.resolve_value_async(selection_set, info, executor),
Some(v) => v.resolve_value_async(selection_set, type_info, executor),
None => Box::pin(future::ok(graphql::Value::Null)),
}
}
}
impl<T, S> resolve::ToInputValue<S> for Option<T>
impl<T, SV, BH> resolve::ToInputValue<SV, BH> for Option<T>
where
T: resolve::ToInputValue<S>,
T: resolve::ToInputValue<SV, BH>,
BH: ?Sized,
{
fn to_input_value(&self) -> graphql::InputValue<S> {
fn to_input_value(&self) -> graphql::InputValue<SV> {
match self {
Some(v) => v.to_input_value(),
None => graphql::InputValue::Null,
@ -73,58 +79,68 @@ where
}
}
impl<'inp, T, S: 'inp> resolve::InputValue<'inp, S> for Option<T>
impl<'i, T, SV, BH> resolve::InputValue<'i, SV, BH> for Option<T>
where
T: resolve::InputValue<'inp, S>,
T: resolve::InputValue<'i, SV, BH>,
SV: 'i,
BH: ?Sized,
{
type Error = <T as resolve::InputValue<'inp, S>>::Error;
type Error = T::Error;
fn try_from_input_value(v: &'inp graphql::InputValue<S>) -> Result<Self, Self::Error> {
fn try_from_input_value(v: &'i graphql::InputValue<SV>) -> Result<Self, Self::Error> {
if v.is_null() {
Ok(None)
} else {
<T as resolve::InputValue<'inp, S>>::try_from_input_value(v).map(Some)
T::try_from_input_value(v).map(Some)
}
}
}
impl<'i, T, Info, S: 'i> graphql::InputType<'i, Info, S> for Option<T>
impl<'i, T, TI, SV, BH> graphql::InputType<'i, TI, SV, BH> for Option<T>
where
T: graphql::InputType<'i, Info, S>,
Info: ?Sized,
T: graphql::InputType<'i, TI, SV, BH>,
TI: ?Sized,
SV: 'i,
BH: ?Sized,
{
fn assert_input_type() {
T::assert_input_type()
}
}
impl<T, S> graphql::OutputType<S> for Option<T>
impl<T, TI, CX, SV, BH> graphql::OutputType<TI, CX, SV, BH> for Option<T>
where
T: graphql::OutputType<S>,
T: graphql::OutputType<TI, CX, SV, BH>,
TI: ?Sized,
CX: ?Sized,
BH: ?Sized,
Self: resolve::ValueAsync<TI, CX, SV, BH>,
{
fn assert_output_type() {
T::assert_output_type()
}
}
impl<T, S> reflect::BaseType<S> for Option<T>
impl<T, BH> reflect::BaseType<BH> for Option<T>
where
T: reflect::BaseType<S>,
T: reflect::BaseType<BH>,
BH: ?Sized,
{
const NAME: reflect::Type = T::NAME;
}
impl<T, S> reflect::BaseSubTypes<S> for Option<T>
impl<T, BH> reflect::BaseSubTypes<BH> for Option<T>
where
T: reflect::BaseSubTypes<S>,
T: reflect::BaseSubTypes<BH>,
BH: ?Sized,
{
const NAMES: reflect::Types = T::NAMES;
}
impl<T, S> reflect::WrappedType<S> for Option<T>
impl<T, BH> reflect::WrappedType<BH> for Option<T>
where
T: reflect::WrappedType<S>,
T: reflect::WrappedType<BH>,
BH: ?Sized,
{
const VALUE: reflect::WrappedValue = reflect::wrap::nullable(T::VALUE);
}
*/

View file

@ -15,11 +15,11 @@ where
TI: ?Sized,
BH: ?Sized,
{
fn meta<'r>(registry: &mut Registry<'r, SV>, info: &TI) -> MetaType<'r, SV>
fn meta<'r>(registry: &mut Registry<'r, SV>, type_info: &TI) -> MetaType<'r, SV>
where
SV: 'r,
{
T::meta(registry, info)
T::meta(registry, type_info)
}
}
@ -29,8 +29,8 @@ where
TI: ?Sized,
BH: ?Sized,
{
fn type_name(info: &TI) -> &str {
T::type_name(info)
fn type_name(type_info: &TI) -> &str {
T::type_name(type_info)
}
}
@ -40,8 +40,8 @@ where
TI: ?Sized,
BH: ?Sized,
{
fn concrete_type_name<'i>(&self, info: &'i TI) -> &'i str {
(**self).concrete_type_name(info)
fn concrete_type_name<'i>(&self, type_info: &'i TI) -> &'i str {
(**self).concrete_type_name(type_info)
}
}

View file

@ -15,11 +15,11 @@ where
TI: ?Sized,
BH: ?Sized,
{
fn meta<'r>(registry: &mut Registry<'r, SV>, info: &TI) -> MetaType<'r, SV>
fn meta<'r>(registry: &mut Registry<'r, SV>, type_info: &TI) -> MetaType<'r, SV>
where
SV: 'r,
{
T::meta(registry, info)
T::meta(registry, type_info)
}
}
@ -29,8 +29,8 @@ where
TI: ?Sized,
BH: ?Sized,
{
fn type_name(info: &TI) -> &str {
T::type_name(info)
fn type_name(type_info: &TI) -> &str {
T::type_name(type_info)
}
}
@ -40,8 +40,8 @@ where
TI: ?Sized,
BH: ?Sized,
{
fn concrete_type_name<'i>(&self, info: &'i TI) -> &'i str {
(**self).concrete_type_name(info)
fn concrete_type_name<'i>(&self, type_info: &'i TI) -> &'i str {
(**self).concrete_type_name(type_info)
}
}

View file

@ -15,11 +15,11 @@ where
TI: ?Sized,
BH: ?Sized,
{
fn meta<'r>(registry: &mut Registry<'r, SV>, info: &TI) -> MetaType<'r, SV>
fn meta<'r>(registry: &mut Registry<'r, SV>, type_info: &TI) -> MetaType<'r, SV>
where
SV: 'r,
{
T::meta(registry, info)
T::meta(registry, type_info)
}
}
@ -29,8 +29,8 @@ where
TI: ?Sized,
BH: ?Sized,
{
fn type_name(info: &TI) -> &str {
T::type_name(info)
fn type_name(type_info: &TI) -> &str {
T::type_name(type_info)
}
}
@ -40,8 +40,8 @@ where
TI: ?Sized,
BH: ?Sized,
{
fn concrete_type_name<'i>(&self, info: &'i TI) -> &'i str {
(**self).concrete_type_name(info)
fn concrete_type_name<'i>(&self, type_info: &'i TI) -> &'i str {
(**self).concrete_type_name(type_info)
}
}