Fix some clippy warnings (#595)

This commit is contained in:
Christian Legnitto 2020-03-31 08:34:50 -07:00 committed by GitHub
parent dbe2c67cb8
commit adc8d7be2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 40 additions and 24 deletions

View file

@ -353,7 +353,7 @@ where
}
/// View the underlying string value, if present.
pub fn as_string_value<'a>(&'a self) -> Option<&'a str> {
pub fn as_string_value(&self) -> Option<&str> {
self.as_scalar_value().and_then(|s| s.as_str())
}

View file

@ -620,7 +620,7 @@ where
self.field_path.construct_path(&mut path);
ExecutionError {
location: self.location().clone(),
location: *self.location(),
path,
error,
}

View file

@ -139,6 +139,7 @@ where
}
impl<'a, S> SchemaType<'a, S> {
/// Create a new schema.
pub fn new<QueryT, MutationT, SubscriptionT>(
query_info: &QueryT::TypeInfo,
mutation_info: &MutationT::TypeInfo,
@ -218,14 +219,17 @@ impl<'a, S> SchemaType<'a, S> {
}
}
/// Add a directive like `skip` or `include`.
pub fn add_directive(&mut self, directive: DirectiveType<'a, S>) {
self.directives.insert(directive.name.clone(), directive);
}
/// Get a type by name.
pub fn type_by_name(&self, name: &str) -> Option<TypeType<S>> {
self.types.get(name).map(|t| TypeType::Concrete(t))
}
/// Get a concrete type by name.
pub fn concrete_type_by_name(&self, name: &str) -> Option<&MetaType<S>> {
self.types.get(name)
}
@ -239,6 +243,7 @@ impl<'a, S> SchemaType<'a, S> {
}
}
/// Get the query type from the schema.
pub fn query_type(&self) -> TypeType<S> {
TypeType::Concrete(
self.types
@ -247,12 +252,14 @@ impl<'a, S> SchemaType<'a, S> {
)
}
/// Get the concrete query type from the schema.
pub fn concrete_query_type(&self) -> &MetaType<S> {
self.types
.get(&self.query_type_name)
.expect("Query type does not exist in schema")
}
/// Get the mutation type from the schema.
pub fn mutation_type(&self) -> Option<TypeType<S>> {
if let Some(ref mutation_type_name) = self.mutation_type_name {
Some(
@ -264,6 +271,7 @@ impl<'a, S> SchemaType<'a, S> {
}
}
/// Get the concrete mutation type from the schema.
pub fn concrete_mutation_type(&self) -> Option<&MetaType<S>> {
self.mutation_type_name.as_ref().map(|name| {
self.concrete_type_by_name(name)
@ -271,6 +279,7 @@ impl<'a, S> SchemaType<'a, S> {
})
}
/// Get the subscription type.
pub fn subscription_type(&self) -> Option<TypeType<S>> {
if let Some(ref subscription_type_name) = self.subscription_type_name {
Some(
@ -282,6 +291,7 @@ impl<'a, S> SchemaType<'a, S> {
}
}
/// Get the concrete subscription type.
pub fn concrete_subscription_type(&self) -> Option<&MetaType<S>> {
self.subscription_type_name.as_ref().map(|name| {
self.concrete_type_by_name(name)
@ -289,14 +299,17 @@ impl<'a, S> SchemaType<'a, S> {
})
}
/// Get a list of types.
pub fn type_list(&self) -> Vec<TypeType<S>> {
self.types.values().map(|t| TypeType::Concrete(t)).collect()
}
/// Get a list of concrete types.
pub fn concrete_type_list(&self) -> Vec<&MetaType<S>> {
self.types.values().collect()
}
/// Make a type.
pub fn make_type(&self, t: &Type) -> TypeType<S> {
match *t {
Type::NonNullNamed(ref n) => TypeType::NonNull(Box::new(
@ -310,14 +323,17 @@ impl<'a, S> SchemaType<'a, S> {
}
}
/// Get a list of directives.
pub fn directive_list(&self) -> Vec<&DirectiveType<S>> {
self.directives.values().collect()
}
/// Get directive by name.
pub fn directive_by_name(&self, name: &str) -> Option<&DirectiveType<S>> {
self.directives.get(name)
}
/// Determine if there is an overlap between types.
pub fn type_overlap(&self, t1: &MetaType<S>, t2: &MetaType<S>) -> bool {
if (t1 as *const MetaType<S>) == (t2 as *const MetaType<S>) {
return true;
@ -334,6 +350,7 @@ impl<'a, S> SchemaType<'a, S> {
}
}
/// A list of possible typeees for a given type.
pub fn possible_types(&self, t: &MetaType<S>) -> Vec<&MetaType<S>> {
match *t {
MetaType::Union(UnionMeta {
@ -357,6 +374,7 @@ impl<'a, S> SchemaType<'a, S> {
}
}
/// If the abstract type is possible.
pub fn is_possible_type(
&self,
abstract_type: &MetaType<S>,
@ -367,6 +385,7 @@ impl<'a, S> SchemaType<'a, S> {
.any(|t| (t as *const MetaType<S>) == (possible_type as *const MetaType<S>))
}
/// If the type is a subtype of another type.
pub fn is_subtype<'b>(&self, sub_type: &Type<'b>, super_type: &Type<'b>) -> bool {
use crate::ast::Type::*;
@ -389,6 +408,7 @@ impl<'a, S> SchemaType<'a, S> {
}
}
/// If the type is a named subtype.
pub fn is_named_subtype(&self, sub_type_name: &str, super_type_name: &str) -> bool {
if sub_type_name == super_type_name {
true

View file

@ -340,6 +340,7 @@ where
///
/// If you instantiate `RootNode` with this as the subscription,
/// no subscriptions will be generated for the schema.
#[derive(Default)]
pub struct EmptySubscription<T> {
phantom: PhantomData<T>,
}

View file

@ -364,8 +364,7 @@ where
} else if let Err(e) = sub_result {
sub_exec.push_error_at(e, start_pos.clone());
}
} else {
if let Some(type_name) = meta_type.name() {
} else if let Some(type_name) = meta_type.name() {
let sub_result = instance
.resolve_into_type_stream(info, type_name, &sub_exec)
.await;
@ -383,7 +382,6 @@ where
}
}
}
}
Value::Object(object)
}

View file

@ -37,7 +37,7 @@ impl<'a, S: Debug> VariableInAllowedPosition<'a, S> {
fn collect_incorrect_usages(
&self,
from: &Scope<'a>,
var_defs: &Vec<&'a (Spanning<&'a str>, VariableDefinition<S>)>,
var_defs: &[&'a (Spanning<&'a str>, VariableDefinition<S>)],
ctx: &mut ValidatorContext<'a, S>,
visited: &mut HashSet<Scope<'a>>,
) {

View file

@ -388,15 +388,13 @@ pub fn graphql_object_internal(args: TokenStream, input: TokenStream) -> TokenSt
/// A proc macro for defining a GraphQL subscription.
#[proc_macro_attribute]
pub fn graphql_subscription(args: TokenStream, input: TokenStream) -> TokenStream {
let gen = impl_object::build_subscription(args, input, false);
gen.into()
impl_object::build_subscription(args, input, false)
}
#[doc(hidden)]
#[proc_macro_attribute]
pub fn graphql_subscription_internal(args: TokenStream, input: TokenStream) -> TokenStream {
let gen = impl_object::build_subscription(args, input, true);
gen.into()
impl_object::build_subscription(args, input, true)
}
#[proc_macro_attribute]

View file

@ -11,7 +11,7 @@
#![deny(warnings)]
#![doc(html_root_url = "https://docs.rs/juniper_subscriptions/0.14.2")]
use std::{borrow::BorrowMut as _, iter::FromIterator, pin::Pin};
use std::{iter::FromIterator, pin::Pin};
use futures::{task::Poll, Stream};
use juniper::{
@ -197,12 +197,11 @@ where
// TODO: iterate over i and (ref field_name, ref val) once
// [this RFC](https://github.com/rust-lang/rust/issues/68354)
// is implemented
for i in 0..obj_len {
for ready in ready_vec.iter_mut().take(obj_len) {
let (field_name, val) = match obj_iterator.next() {
Some(v) => v,
None => break,
};
let ready = ready_vec[i].borrow_mut();
if ready.is_some() {
continue;

View file

@ -343,7 +343,7 @@ where
};
let get_filter = warp::get()
.and(context_extractor.clone())
.and(context_extractor)
.and(warp::filters::query::query())
.and_then(handle_get_request);