Fix some clippy lints ()

* Fix some clippy lints
This commit is contained in:
Christian Legnitto 2020-03-13 22:03:36 -07:00 committed by GitHub
parent fd4290462c
commit 3b5cf4ad64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 131 additions and 175 deletions

View file

@ -41,13 +41,10 @@ where
InputValue::Null => LookAheadValue::Null,
InputValue::Scalar(ref s) => LookAheadValue::Scalar(s),
InputValue::Enum(ref e) => LookAheadValue::Enum(e),
InputValue::Variable(ref name) => {
let value = vars
.get(name)
.map(|v| Self::from_input_value(v, vars))
.unwrap_or(LookAheadValue::Null);
value
}
InputValue::Variable(ref name) => vars
.get(name)
.map(|v| Self::from_input_value(v, vars))
.unwrap_or(LookAheadValue::Null),
InputValue::List(ref l) => LookAheadValue::List(
l.iter()
.map(|i| LookAheadValue::from_input_value(&i.item, vars))

View file

@ -670,9 +670,8 @@ where
{
let mut fragments = vec![];
for def in document.iter() {
match def {
Definition::Fragment(f) => fragments.push(f),
_ => (),
if let Definition::Fragment(f) = def {
fragments.push(f)
};
}
@ -761,9 +760,8 @@ where
{
let mut fragments = vec![];
for def in document.iter() {
match def {
Definition::Fragment(f) => fragments.push(f),
_ => (),
if let Definition::Fragment(f) = def {
fragments.push(f)
};
}
@ -850,20 +848,17 @@ where
{
let mut operation = None;
for def in document {
match def {
Definition::Operation(op) => {
if operation_name.is_none() && operation.is_some() {
return Err(GraphQLError::MultipleOperationsProvided);
}
let move_op = operation_name.is_none()
|| op.item.name.as_ref().map(|s| s.item) == operation_name;
if move_op {
operation = Some(op);
}
if let Definition::Operation(op) = def {
if operation_name.is_none() && operation.is_some() {
return Err(GraphQLError::MultipleOperationsProvided);
}
let move_op =
operation_name.is_none() || op.item.name.as_ref().map(|s| s.item) == operation_name;
if move_op {
operation = Some(op);
}
_ => (),
};
}
let op = match operation {
@ -966,10 +961,9 @@ where
}
fn insert_placeholder(&mut self, name: Name, of_type: Type<'r>) {
if !self.types.contains_key(&name) {
self.types
.insert(name, MetaType::Placeholder(PlaceholderMeta { of_type }));
}
self.types
.entry(name)
.or_insert(MetaType::Placeholder(PlaceholderMeta { of_type }));
}
/// Create a scalar meta type

View file

@ -22,7 +22,7 @@ use crate::{
};
#[doc(hidden)]
pub static RFC3339_FORMAT: &'static str = "%Y-%m-%dT%H:%M:%S%.f%:z";
pub static RFC3339_FORMAT: &str = "%Y-%m-%dT%H:%M:%S%.f%:z";
graphql_scalar!(DateTime<FixedOffset> as "DateTimeFixedOffset" where Scalar = <S>{
description: "DateTime"

View file

@ -1,3 +1,5 @@
#![allow(clippy::needless_lifetimes)]
use uuid::Uuid;
use crate::{
@ -18,7 +20,8 @@ graphql_scalar!(Uuid where Scalar = <S> {
.and_then(|s| Uuid::parse_str(s).ok())
}
from_str<'a>(value: ScalarToken<'a>) -> ParseScalarResult<'a, S> {
from_str<'a>(value: ScalarToken<'_>) -> ParseScalarResult<S> {
if let ScalarToken::String(value) = value {
Ok(S::from(value.to_owned()))
} else {

View file

@ -65,7 +65,7 @@ where
Token::Name("fragment") => Ok(Definition::Fragment(parse_fragment_definition(
parser, schema,
)?)),
_ => Err(parser.next()?.map(ParseError::UnexpectedToken)),
_ => Err(parser.next_token()?.map(ParseError::UnexpectedToken)),
}
}
@ -93,7 +93,7 @@ where
},
))
} else {
let start_pos = parser.peek().start.clone();
let start_pos = parser.peek().start;
let operation_type = parse_operation_type(parser)?;
let op = match operation_type.item {
OperationType::Query => Some(schema.concrete_query_type()),
@ -228,7 +228,7 @@ where
match parser.peek().item {
Token::Name("on") => {
parser.next()?;
parser.next_token()?;
let name = parser.expect_name()?;
let fields = schema
@ -291,7 +291,7 @@ where
},
)))
}
_ => Err(parser.next()?.map(ParseError::UnexpectedToken)),
_ => Err(parser.next_token()?.map(ParseError::UnexpectedToken)),
}
}
@ -396,10 +396,12 @@ where
fn parse_operation_type<'a>(parser: &mut Parser<'a>) -> ParseResult<'a, OperationType> {
match parser.peek().item {
Token::Name("query") => Ok(parser.next()?.map(|_| OperationType::Query)),
Token::Name("mutation") => Ok(parser.next()?.map(|_| OperationType::Mutation)),
Token::Name("subscription") => Ok(parser.next()?.map(|_| OperationType::Subscription)),
_ => Err(parser.next()?.map(ParseError::UnexpectedToken)),
Token::Name("query") => Ok(parser.next_token()?.map(|_| OperationType::Query)),
Token::Name("mutation") => Ok(parser.next_token()?.map(|_| OperationType::Mutation)),
Token::Name("subscription") => {
Ok(parser.next_token()?.map(|_| OperationType::Subscription))
}
_ => Err(parser.next_token()?.map(ParseError::UnexpectedToken)),
}
}

View file

@ -135,7 +135,7 @@ impl<'a> Lexer<'a> {
fn emit_single_char(&mut self, t: Token<'a>) -> Spanning<Token<'a>> {
assert!(self.position.index() <= self.length);
let start_pos = self.position.clone();
let start_pos = self.position;
self.next_char()
.expect("Internal error in GraphQL lexer: emit_single_char reached EOF");
@ -167,13 +167,12 @@ impl<'a> Lexer<'a> {
}
fn scan_ellipsis(&mut self) -> LexerResult<'a> {
let start_pos = self.position.clone();
let start_pos = self.position;
for _ in 0..3 {
let (_, ch) = self.next_char().ok_or(Spanning::zero_width(
&self.position,
LexerError::UnexpectedEndOfFile,
))?;
let (_, ch) = self.next_char().ok_or_else(|| {
Spanning::zero_width(&self.position, LexerError::UnexpectedEndOfFile)
})?;
if ch != '.' {
return Err(Spanning::zero_width(
&start_pos,

View file

@ -54,7 +54,7 @@ impl<'a> Parser<'a> {
}
#[doc(hidden)]
pub fn next(&mut self) -> ParseResult<'a, Token<'a>> {
pub fn next_token(&mut self) -> ParseResult<'a, Token<'a>> {
if self.tokens.len() == 1 {
Err(Spanning::start_end(
&self.peek().start,
@ -69,9 +69,9 @@ impl<'a> Parser<'a> {
#[doc(hidden)]
pub fn expect(&mut self, expected: &Token) -> ParseResult<'a, Token<'a>> {
if &self.peek().item != expected {
Err(self.next()?.map(ParseError::UnexpectedToken))
Err(self.next_token()?.map(ParseError::UnexpectedToken))
} else {
self.next()
self.next_token()
}
}
@ -81,7 +81,7 @@ impl<'a> Parser<'a> {
expected: &Token,
) -> Result<Option<Spanning<Token<'a>>>, Spanning<ParseError<'a>>> {
if &self.peek().item == expected {
Ok(Some(self.next()?))
Ok(Some(self.next_token()?))
} else if self.peek().item == Token::EndOfFile {
Err(Spanning::zero_width(
&self.peek().start,
@ -173,7 +173,7 @@ impl<'a> Parser<'a> {
Spanning {
item: Token::Name(_),
..
} => Ok(self.next()?.map(|token| {
} => Ok(self.next_token()?.map(|token| {
if let Token::Name(name) = token {
name
} else {
@ -188,7 +188,7 @@ impl<'a> Parser<'a> {
&self.peek().end,
ParseError::UnexpectedEndOfFile,
)),
_ => Err(self.next()?.map(ParseError::UnexpectedToken)),
_ => Err(self.next_token()?.map(ParseError::UnexpectedToken)),
}
}
}

View file

@ -58,7 +58,7 @@ where
item: Token::Scalar(scalar),
start,
end,
} = parser.next()?
} = parser.next_token()?
{
(s.parse_fn)(scalar)
.map(|s| Spanning::start_end(&start, &end, InputValue::Scalar(s)))
@ -78,7 +78,7 @@ where
item: Token::Scalar(token),
start,
end,
} = parser.next()?
} = parser.next_token()?
{
parse_scalar_literal_by_infered_type(token, &start, &end, schema)
} else {
@ -91,21 +91,21 @@ where
..
},
_,
) => Ok(parser.next()?.map(|_| InputValue::scalar(true))),
) => Ok(parser.next_token()?.map(|_| InputValue::scalar(true))),
(
&Spanning {
item: Token::Name("false"),
..
},
_,
) => Ok(parser.next()?.map(|_| InputValue::scalar(false))),
) => Ok(parser.next_token()?.map(|_| InputValue::scalar(false))),
(
&Spanning {
item: Token::Name("null"),
..
},
_,
) => Ok(parser.next()?.map(|_| InputValue::null())),
) => Ok(parser.next_token()?.map(|_| InputValue::null())),
(
&Spanning {
item: Token::Name(name),
@ -113,9 +113,9 @@ where
},
_,
) => Ok(parser
.next()?
.next_token()?
.map(|_| InputValue::enum_value(name.to_owned()))),
_ => Err(parser.next()?.map(ParseError::UnexpectedToken)),
_ => Err(parser.next_token()?.map(ParseError::UnexpectedToken)),
}
}

View file

@ -194,7 +194,7 @@ where
&meta_field.arguments,
);
let pos = start_pos.clone();
let pos = *start_pos;
let is_non_null = meta_field.field_type.is_non_null();
let response_name = response_name.to_string();

View file

@ -547,13 +547,12 @@ pub(crate) fn merge_key_into<S>(result: &mut Object<S>, response_name: &str, val
dest_list
.iter_mut()
.zip(src_list.into_iter())
.for_each(|(d, s)| match d {
&mut Value::Object(ref mut d_obj) => {
.for_each(|(d, s)| {
if let Value::Object(ref mut d_obj) = *d {
if let Value::Object(s_obj) = s {
merge_maps(d_obj, s_obj);
}
}
_ => {}
});
}
}

View file

@ -1,4 +1,3 @@
use futures;
use serde_derive::{Deserialize, Serialize};
use std::{char, convert::From, marker::PhantomData, ops::Deref, u32};
@ -291,7 +290,7 @@ graphql_scalar!(f64 as "Float" where Scalar = <S>{
///
/// If you instantiate `RootNode` with this as the mutation, no mutation will be
/// generated for the schema.
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct EmptyMutation<T> {
phantom: PhantomData<T>,
}

View file

@ -225,7 +225,7 @@ where
// TODO: avoid this bad duplicate as_str() call. (value system refactor)
InputValue::Scalar(ref scalar) if scalar.as_str().is_some() => {
if let Some(ref name) = scalar.as_str() {
if !meta.values.iter().any(|ev| &ev.name == *name) {
if !meta.values.iter().any(|ev| ev.name == *name) {
errors.push(unification_error(
var_name,
var_pos,
@ -337,7 +337,7 @@ fn unification_error<'a>(
r#"Variable "${}" got invalid value. {}{}."#,
var_name, path, message,
),
&[var_pos.clone()],
&[*var_pos],
)
}

View file

@ -124,11 +124,11 @@ where
self.1.exit_argument(ctx, arg);
}
fn enter_selection_set(&mut self, ctx: &mut ValidatorContext<'a, S>, s: &'a Vec<Selection<S>>) {
fn enter_selection_set(&mut self, ctx: &mut ValidatorContext<'a, S>, s: &'a [Selection<S>]) {
self.0.enter_selection_set(ctx, s);
self.1.enter_selection_set(ctx, s);
}
fn exit_selection_set(&mut self, ctx: &mut ValidatorContext<'a, S>, s: &'a Vec<Selection<S>>) {
fn exit_selection_set(&mut self, ctx: &mut ValidatorContext<'a, S>, s: &'a [Selection<S>]) {
self.0.exit_selection_set(ctx, s);
self.1.exit_selection_set(ctx, s);
}

View file

@ -27,16 +27,13 @@ where
let type_name = parent_type.name().unwrap_or("<unknown>");
if parent_type.field_by_name(field_name.item).is_none() {
match *parent_type {
MetaType::Union(..) => {
// You can query for `__typename` on a union,
// but it isn't a field on the union...it is
// instead on the resulting object returned.
if field_name.item == "__typename" {
return;
}
if let MetaType::Union(..) = *parent_type {
// You can query for `__typename` on a union,
// but it isn't a field on the union...it is
// instead on the resulting object returned.
if field_name.item == "__typename" {
return;
}
_ => {}
}
context.report_error(

View file

@ -50,7 +50,7 @@ where
.next();
if let Some(name) = invalid_type_name {
context.report_error(&error_message(None, name), &[type_cond.start.clone()]);
context.report_error(&error_message(None, name), &[type_cond.start]);
}
}
}

View file

@ -123,7 +123,7 @@ where
{
ctx.report_error(
&misplaced_error_message(directive_name, current_location),
&[directive.start.clone()],
&[directive.start],
);
}
}

View file

@ -112,10 +112,8 @@ impl<'a> CycleDetector<'a> {
node
};
self.errors.push(RuleError::new(
&error_message(name),
&[err_pos.start.clone()],
));
self.errors
.push(RuleError::new(&error_message(name), &[err_pos.start]));
} else if !self.visited.contains(name) {
path.push(node);
self.detect_from(name, path);

View file

@ -695,7 +695,7 @@ where
fn enter_selection_set(
&mut self,
ctx: &mut ValidatorContext<'a, S>,
selection_set: &'a Vec<Selection<S>>,
selection_set: &'a [Selection<S>],
) {
for Conflict(ConflictReason(reason_name, reason_msg), mut p1, mut p2) in
self.find_conflicts_within_selection_set(ctx.parent_type(), selection_set, ctx)

View file

@ -36,10 +36,7 @@ where
) {
match self.known_names.entry(arg_name.item) {
Entry::Occupied(e) => {
ctx.report_error(
&error_message(arg_name.item),
&[e.get().clone(), arg_name.start],
);
ctx.report_error(&error_message(arg_name.item), &[*e.get(), arg_name.start]);
}
Entry::Vacant(e) => {
e.insert(arg_name.start);

View file

@ -30,7 +30,7 @@ where
Entry::Occupied(e) => {
context.report_error(
&duplicate_message(f.item.name.item),
&[e.get().clone(), f.item.name.start],
&[*e.get(), f.item.name.start],
);
}
Entry::Vacant(e) => {

View file

@ -47,7 +47,7 @@ where
Entry::Occupied(e) => {
ctx.report_error(
&error_message(&field_name.item),
&[e.get().clone(), field_name.start],
&[*e.get(), field_name.start],
);
}
Entry::Vacant(e) => {

View file

@ -29,7 +29,7 @@ where
if let Some(ref op_name) = op.item.name {
match self.names.entry(op_name.item) {
Entry::Occupied(e) => {
ctx.report_error(&error_message(op_name.item), &[e.get().clone(), op.start]);
ctx.report_error(&error_message(op_name.item), &[*e.get(), op.start]);
}
Entry::Vacant(e) => {
e.insert(op.start);

View file

@ -36,10 +36,7 @@ where
) {
match self.names.entry(var_name.item) {
Entry::Occupied(e) => {
ctx.report_error(
&error_message(var_name.item),
&[e.get().clone(), var_name.start],
);
ctx.report_error(&error_message(var_name.item), &[*e.get(), var_name.start]);
}
Entry::Vacant(e) => {
e.insert(var_name.start);

View file

@ -71,8 +71,8 @@ where
) {
}
fn enter_selection_set(&mut self, _: &mut ValidatorContext<'a, S>, _: &'a Vec<Selection<S>>) {}
fn exit_selection_set(&mut self, _: &mut ValidatorContext<'a, S>, _: &'a Vec<Selection<S>>) {}
fn enter_selection_set(&mut self, _: &mut ValidatorContext<'a, S>, _: &'a [Selection<S>]) {}
fn exit_selection_set(&mut self, _: &mut ValidatorContext<'a, S>, _: &'a [Selection<S>]) {}
fn enter_field(&mut self, _: &mut ValidatorContext<'a, S>, _: &'a Spanning<Field<S>>) {}
fn exit_field(&mut self, _: &mut ValidatorContext<'a, S>, _: &'a Spanning<Field<S>>) {}

View file

@ -25,11 +25,8 @@ pub fn visit<'a, A, B, S>(
v.exit_document(ctx, d);
}
fn visit_definitions<'a, S, V>(
v: &mut V,
ctx: &mut ValidatorContext<'a, S>,
d: &'a Vec<Definition<S>>,
) where
fn visit_definitions<'a, S, V>(v: &mut V, ctx: &mut ValidatorContext<'a, S>, d: &'a [Definition<S>])
where
S: ScalarValue,
V: Visitor<'a, S>,
{
@ -166,7 +163,7 @@ fn visit_directives<'a, S, V>(
.map(|d| &d.arguments);
v.enter_directive(ctx, directive);
visit_arguments(v, ctx, &directive_arguments, &directive.item.arguments);
visit_arguments(v, ctx, directive_arguments, &directive.item.arguments);
v.exit_directive(ctx, directive);
}
}
@ -175,7 +172,7 @@ fn visit_directives<'a, S, V>(
fn visit_arguments<'a, S, V>(
v: &mut V,
ctx: &mut ValidatorContext<'a, S>,
meta_args: &Option<&Vec<Argument<'a, S>>>,
meta_args: Option<&Vec<Argument<'a, S>>>,
arguments: &'a Option<Spanning<Arguments<S>>>,
) where
S: ScalarValue,
@ -201,7 +198,7 @@ fn visit_arguments<'a, S, V>(
fn visit_selection_set<'a, S, V>(
v: &mut V,
ctx: &mut ValidatorContext<'a, S>,
selection_set: &'a Vec<Selection<S>>,
selection_set: &'a [Selection<S>],
) where
S: ScalarValue,
V: Visitor<'a, S>,
@ -250,7 +247,7 @@ fn visit_field<'a, S, V>(
ctx.with_pushed_type(field_type, |ctx| {
v.enter_field(ctx, field);
visit_arguments(v, ctx, &field_args, &field.item.arguments);
visit_arguments(v, ctx, field_args, &field.item.arguments);
visit_directives(v, ctx, &field.item.directives);
if let Some(ref selection_set) = field.item.selection_set {

View file

@ -82,11 +82,8 @@ impl<S> Object<S> {
self.key_value_list
.sort_by(|(key1, _), (key2, _)| key1.cmp(key2));
for (_, ref mut value) in &mut self.key_value_list {
match value {
Value::Object(ref mut o) => {
o.sort_by_field();
}
_ => {}
if let Value::Object(ref mut o) = value {
o.sort_by_field();
}
}
}

View file

@ -102,14 +102,11 @@ impl ObjFieldAttrs {
continue;
}
match item {
NestedMeta::Meta(Meta::Path(ref path)) => {
if path.is_ident("default") {
res.default = true;
continue;
}
if let NestedMeta::Meta(Meta::Path(ref path)) = item {
if path.is_ident("default") {
res.default = true;
continue;
}
_ => {}
}
panic!(format!(
"Unknown attribute for #[derive(GraphQLInputObject)]: {:?}",

View file

@ -24,7 +24,7 @@ pub fn build_derive_object(ast: syn::DeriveInput, is_internal: bool) -> TokenStr
panic!("Invalid #[graphql(...)] attribute: {}", e);
}
};
if attrs.interfaces.len() > 0 {
if !attrs.interfaces.is_empty() {
panic!("Invalid #[graphql(...)] attribute 'interfaces': #[derive(GraphQLObject) does not support 'interfaces'");
}
let ident = &ast.ident;

View file

@ -50,7 +50,7 @@ impl syn::parse::Parse for TransparentAttributes {
}
impl TransparentAttributes {
fn from_attrs(attrs: &Vec<syn::Attribute>) -> syn::parse::Result<Self> {
fn from_attrs(attrs: &[syn::Attribute]) -> syn::parse::Result<Self> {
match util::find_graphql_attr(attrs) {
Some(attr) => {
let mut parsed: TransparentAttributes = attr.parse_args()?;
@ -97,7 +97,7 @@ fn impl_scalar_struct(
}
};
let inner_ty = &field.ty;
let name = attrs.name.unwrap_or(ident.to_string());
let name = attrs.name.unwrap_or_else(|| ident.to_string());
let crate_name = if is_internal {
quote!(crate)

View file

@ -20,7 +20,7 @@ pub fn build_object(args: TokenStream, body: TokenStream, is_internal: bool) ->
description: _impl.description,
fields: Vec::new(),
generics: _impl.generics.clone(),
interfaces: if _impl.attrs.interfaces.len() > 0 {
interfaces: if !_impl.attrs.interfaces.is_empty() {
Some(_impl.attrs.interfaces)
} else {
None

View file

@ -90,7 +90,7 @@ pub fn impl_union(
.iter()
.find(|&m| _impl.parse_resolve_method(&m).is_ok());
if _impl.methods.is_empty() || !method.is_some() {
if _impl.methods.is_empty() || method.is_none() {
return Err(MacroError::new(
_impl.target_type.span(),
"Invalid impl body: expected one method with signature: fn resolve(&self) { ... }"

View file

@ -369,16 +369,14 @@ impl User {
*/
#[proc_macro_attribute]
pub fn graphql_object(args: TokenStream, input: TokenStream) -> TokenStream {
let gen = impl_object::build_object(args, input, false);
gen.into()
impl_object::build_object(args, input, false)
}
/// A proc macro for defining a GraphQL object.
#[doc(hidden)]
#[proc_macro_attribute]
pub fn graphql_object_internal(args: TokenStream, input: TokenStream) -> TokenStream {
let gen = impl_object::build_object(args, input, true);
gen.into()
impl_object::build_object(args, input, true)
}
#[proc_macro_attribute]

View file

@ -83,13 +83,13 @@ pub struct DeprecationAttr {
pub reason: Option<String>,
}
pub fn find_graphql_attr(attrs: &Vec<Attribute>) -> Option<&Attribute> {
pub fn find_graphql_attr(attrs: &[Attribute]) -> Option<&Attribute> {
attrs
.iter()
.find(|attr| path_eq_single(&attr.path, "graphql"))
}
pub fn get_deprecated(attrs: &Vec<Attribute>) -> Option<DeprecationAttr> {
pub fn get_deprecated(attrs: &[Attribute]) -> Option<DeprecationAttr> {
for attr in attrs {
match attr.parse_meta() {
Ok(Meta::List(ref list)) if list.path.is_ident("deprecated") => {
@ -131,7 +131,7 @@ fn get_deprecated_meta_list(list: &MetaList) -> DeprecationAttr {
}
// Gets doc comment.
pub fn get_doc_comment(attrs: &Vec<Attribute>) -> Option<String> {
pub fn get_doc_comment(attrs: &[Attribute]) -> Option<String> {
if let Some(items) = get_doc_attr(attrs) {
if let Some(doc_strings) = get_doc_strings(&items) {
return Some(join_doc_strings(&doc_strings));
@ -150,13 +150,7 @@ fn join_doc_strings(docs: &Vec<String>) -> String {
docs.iter()
.map(|s| s.as_str().trim_end())
// Trim leading space.
.map(|s| {
if s.chars().next() == Some(' ') {
&s[1..]
} else {
s
}
})
.map(|s| if s.starts_with(' ') { &s[1..] } else { s })
// Add newline, exept when string ends in a continuation backslash or is the last line.
.enumerate()
.fold(String::new(), |mut buffer, (index, s)| {
@ -174,13 +168,13 @@ fn join_doc_strings(docs: &Vec<String>) -> String {
}
// Gets doc strings from doc comment attributes.
fn get_doc_strings(items: &Vec<MetaNameValue>) -> Option<Vec<String>> {
fn get_doc_strings(items: &[MetaNameValue]) -> Option<Vec<String>> {
let comments = items
.iter()
.filter_map(|item| {
if item.path.is_ident("doc") {
match item.lit {
Lit::Str(ref strlit) => Some(strlit.value().to_string()),
Lit::Str(ref strlit) => Some(strlit.value()),
_ => panic!("doc attributes only have string literal"),
}
} else {
@ -188,15 +182,15 @@ fn get_doc_strings(items: &Vec<MetaNameValue>) -> Option<Vec<String>> {
}
})
.collect::<Vec<_>>();
if comments.len() > 0 {
Some(comments)
} else {
if comments.is_empty() {
None
} else {
Some(comments)
}
}
// Gets doc comment attributes.
fn get_doc_attr(attrs: &Vec<Attribute>) -> Option<Vec<MetaNameValue>> {
fn get_doc_attr(attrs: &[Attribute]) -> Option<Vec<MetaNameValue>> {
let mut docs = Vec::new();
for attr in attrs {
match attr.parse_meta() {
@ -211,7 +205,7 @@ fn get_doc_attr(attrs: &Vec<Attribute>) -> Option<Vec<MetaNameValue>> {
}
// Get the nested items of a a #[graphql(...)] attribute.
pub fn get_graphql_attr(attrs: &Vec<Attribute>) -> Option<Vec<NestedMeta>> {
pub fn get_graphql_attr(attrs: &[Attribute]) -> Option<Vec<NestedMeta>> {
for attr in attrs {
match attr.parse_meta() {
Ok(Meta::List(ref list)) if list.path.is_ident("graphql") => {
@ -233,15 +227,7 @@ pub fn keyed_item_value(
&NestedMeta::Meta(Meta::NameValue(ref nameval)) if nameval.path.is_ident(name) => {
match &nameval.lit {
// We have a string attribute value.
&Lit::Str(ref strlit) => match validation {
// AttributeValidation::Bare => {
// panic!(format!(
// "Invalid format for attribute \"{:?}\": expected a bare attribute without a value",
// item
// ));
// }
_ => Some(AttributeValue::String(strlit.value())),
},
&Lit::Str(ref strlit) => Some(AttributeValue::String(strlit.value())),
_ => None,
}
}
@ -402,7 +388,7 @@ impl syn::parse::Parse for ObjectAttributes {
}
impl ObjectAttributes {
pub fn from_attrs(attrs: &Vec<syn::Attribute>) -> syn::parse::Result<Self> {
pub fn from_attrs(attrs: &[syn::Attribute]) -> syn::parse::Result<Self> {
let attr_opt = find_graphql_attr(attrs);
if let Some(attr) = attr_opt {
// Need to unwrap outer (), which are not present for proc macro attributes,
@ -692,7 +678,8 @@ impl GraphQLTypeDefiniton {
None => quote!(),
};
let code = match arg.default.as_ref() {
// Code.
match arg.default.as_ref() {
Some(value) => quote!(
.argument(
registry.arg_with_default::<#arg_type>(#arg_name, &#value, info)
@ -705,8 +692,7 @@ impl GraphQLTypeDefiniton {
#description
)
),
};
code
}
});
let description = match field.description.as_ref() {

View file

@ -3,7 +3,6 @@
#[cfg(test)]
extern crate reqwest;
use futures;
use hyper::{
header::{self, HeaderValue},
Body, Method, Request, Response, StatusCode,
@ -29,8 +28,8 @@ where
QueryT::TypeInfo: Send + Sync,
MutationT::TypeInfo: Send + Sync,
{
match request.method() {
&Method::GET => {
match *request.method() {
Method::GET => {
let gql_req = parse_get_req(request);
match gql_req {
@ -38,7 +37,7 @@ where
Err(err) => Ok(render_error(err)),
}
}
&Method::POST => {
Method::POST => {
let gql_req = parse_post_req(request.into_body()).await;
match gql_req {
@ -63,8 +62,8 @@ where
QueryT::TypeInfo: Send + Sync,
MutationT::TypeInfo: Send + Sync,
{
match request.method() {
&Method::GET => {
match *request.method() {
Method::GET => {
let gql_req = parse_get_req(request);
match gql_req {
@ -72,7 +71,7 @@ where
Err(err) => Ok(render_error(err)),
}
}
&Method::POST => {
Method::POST => {
let gql_req = parse_post_req(request.into_body()).await;
match gql_req {
@ -102,7 +101,7 @@ async fn parse_post_req<S: ScalarValue>(
) -> Result<GraphQLRequest<S>, GraphQLRequestError> {
let chunk = hyper::body::to_bytes(body)
.await
.map_err(|err| GraphQLRequestError::BodyHyper(err))?;
.map_err(GraphQLRequestError::BodyHyper)?;
let input = String::from_utf8(chunk.iter().cloned().collect())
.map_err(GraphQLRequestError::BodyUtf8)?;

View file

@ -91,11 +91,11 @@ where
QueryT: GraphQLType<S, Context = CtxT>,
MutationT: GraphQLType<S, Context = CtxT>,
{
match self {
&GraphQLBatchRequest::Single(ref request) => {
match *self {
GraphQLBatchRequest::Single(ref request) => {
GraphQLBatchResponse::Single(request.execute_sync(root_node, context))
}
&GraphQLBatchRequest::Batch(ref requests) => GraphQLBatchResponse::Batch(
GraphQLBatchRequest::Batch(ref requests) => GraphQLBatchResponse::Batch(
requests
.iter()
.map(|request| request.execute_sync(root_node, context))
@ -119,11 +119,11 @@ where
S: ScalarValue,
{
fn is_ok(&self) -> bool {
match self {
&GraphQLBatchResponse::Single(ref response) => response.is_ok(),
&GraphQLBatchResponse::Batch(ref responses) => responses
.iter()
.fold(true, |ok, response| ok && response.is_ok()),
match *self {
GraphQLBatchResponse::Single(ref response) => response.is_ok(),
GraphQLBatchResponse::Batch(ref responses) => {
responses.iter().all(|response| response.is_ok())
}
}
}
}
@ -343,7 +343,7 @@ where
match serde_json::from_str(&body) {
Ok(value) => Success(GraphQLRequest(value)),
Err(failure) => return Failure((Status::BadRequest, format!("{}", failure))),
Err(failure) => Failure((Status::BadRequest, format!("{}", failure))),
}
}
}