Impl macro for scalars, vol.2 [skip ci]

This commit is contained in:
tyranron 2022-06-17 21:30:30 +02:00
parent f2718cc01a
commit a05a0091f6
No known key found for this signature in database
GPG key ID: 762E144FB230A4F0
2 changed files with 11 additions and 15 deletions

View file

@ -4,6 +4,7 @@ use std::{
borrow::Cow,
cmp::Ordering,
collections::{hash_map, HashMap},
convert,
fmt::{Debug, Display},
sync::{Arc, RwLock},
};
@ -1297,14 +1298,12 @@ impl<'r, S: 'r> Registry<'r, S> {
T: resolve::TypeName<TI> + resolve::InputValueOwned<S> + resolve::ScalarToken<S>,
TI: ?Sized,
'ti: 'r,
F: FnOnce(&mut ScalarMeta<'r, S>),
F: FnOnce(ScalarMeta<'r, S>) -> ScalarMeta<'r, S>,
S: Clone,
{
self.entry_type::<T, _>(type_info)
.or_insert_with(move || {
let mut scalar = ScalarMeta::new_reworked::<T, _>(T::type_name(type_info));
customize(&mut scalar);
scalar.into_meta()
customize(ScalarMeta::new_reworked::<T, _>(T::type_name(type_info))).into_meta()
})
.clone()
}
@ -1326,9 +1325,7 @@ impl<'r, S: 'r> Registry<'r, S> {
'ti: 'r,
S: Clone,
{
// TODO: Use `drop` instead of `|_| {}` once Rust's inference becomes
// better for HRTB closures.
self.register_scalar_unsized_with::<T, TI, _>(type_info, |_| {})
self.register_scalar_unsized_with::<T, TI, _>(type_info, convert::identity)
}
/// Builds a [`ScalarMeta`] information for the specified non-[`Sized`]
@ -1351,14 +1348,12 @@ impl<'r, S: 'r> Registry<'r, S> {
T: resolve::TypeName<TI> + resolve::InputValueAsRef<S> + resolve::ScalarToken<S> + ?Sized,
TI: ?Sized,
'ti: 'r,
F: FnOnce(&mut ScalarMeta<'r, S>),
F: FnOnce(ScalarMeta<'r, S>) -> ScalarMeta<'r, S>,
S: Clone,
{
self.entry_type::<T, _>(type_info)
.or_insert_with(move || {
let mut scalar = ScalarMeta::new_unsized::<T, _>(T::type_name(type_info));
customize(&mut scalar);
scalar.into_meta()
customize(ScalarMeta::new_unsized::<T, _>(T::type_name(type_info))).into_meta()
})
.clone()
}

View file

@ -529,9 +529,10 @@ impl Definition {
let predicates = &mut generics.make_where_clause().predicates;
predicates.push(parse_quote! { #sv: Clone });
predicates.push(parse_quote! {
Self: ::juniper::resolve::TypeName<#inf, #bh>
+ ::juniper::resolve::ScalarToken<#sv, #bh>
+ ::juniper::resolve::InputValueOwned<#sv, #bh>
::juniper::behavior::Coerce<Self, #bh>:
::juniper::resolve::TypeName<#inf, #bh>
+ ::juniper::resolve::ScalarToken<#sv, #bh>
+ ::juniper::resolve::InputValueOwned<#sv, #bh>
});
let (impl_gens, _, where_clause) = generics.split_for_impl();
@ -561,7 +562,7 @@ impl Definition {
::juniper::behavior::Coerce<Self, #bh>, _, _,
>(type_info, |meta| {
meta#description
#specified_by_url;
#specified_by_url
})
}
}