diff --git a/examples/warp_async/src/main.rs b/examples/warp_async/src/main.rs index 7f1b902f..7e1babbf 100644 --- a/examples/warp_async/src/main.rs +++ b/examples/warp_async/src/main.rs @@ -81,9 +81,9 @@ async fn main() { let homepage = warp::path::end().map(|| { Response::builder() .header("content-type", "text/html") - .body(format!( - "

juniper_warp

visit /graphiql" - )) + .body( + "

juniper_warp

visit /graphiql", + ) }); log::info!("Listening on 127.0.0.1:8080"); diff --git a/juniper/src/ast.rs b/juniper/src/ast.rs index df32ecec..4d410883 100644 --- a/juniper/src/ast.rs +++ b/juniper/src/ast.rs @@ -192,10 +192,7 @@ impl<'a> Type<'a> { /// Determines if a type only can represent non-null values. pub fn is_non_null(&self) -> bool { - match *self { - Type::NonNullNamed(_) | Type::NonNullList(_) => true, - _ => false, - } + matches!(*self, Type::NonNullNamed(_) | Type::NonNullList(_)) } } @@ -328,18 +325,12 @@ where /// Does the value represent null? pub fn is_null(&self) -> bool { - match *self { - InputValue::Null => true, - _ => false, - } + matches!(*self, InputValue::Null) } /// Does the value represent a variable? pub fn is_variable(&self) -> bool { - match *self { - InputValue::Variable(_) => true, - _ => false, - } + matches!(*self, InputValue::Variable(_)) } /// View the underlying enum value, if present. diff --git a/juniper/src/parser/lexer.rs b/juniper/src/parser/lexer.rs index 50504644..d423d794 100644 --- a/juniper/src/parser/lexer.rs +++ b/juniper/src/parser/lexer.rs @@ -513,15 +513,15 @@ fn is_source_char(c: char) -> bool { } fn is_name_start(c: char) -> bool { - c == '_' || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') + c == '_' || ('A'..='Z').contains(&c) || ('a'..='z').contains(&c) } fn is_name_cont(c: char) -> bool { - is_name_start(c) || (c >= '0' && c <= '9') + is_name_start(c) || ('0'..='9').contains(&c) } fn is_number_start(c: char) -> bool { - c == '-' || (c >= '0' && c <= '9') + c == '-' || ('0'..='9').contains(&c) } impl fmt::Display for LexerError { diff --git a/juniper/src/schema/meta.rs b/juniper/src/schema/meta.rs index be64e06f..9d1342d7 100644 --- a/juniper/src/schema/meta.rs +++ b/juniper/src/schema/meta.rs @@ -348,40 +348,28 @@ impl<'a, S> MetaType<'a, S> { /// /// Objects, interfaces, and unions are composite. pub fn is_composite(&self) -> bool { - match *self { - MetaType::Object(_) | MetaType::Interface(_) | MetaType::Union(_) => true, - _ => false, - } + matches!(*self, MetaType::Object(_) | MetaType::Interface(_) | MetaType::Union(_)) } /// Returns true if the type can occur in leaf positions in queries /// /// Only enums and scalars are leaf types. pub fn is_leaf(&self) -> bool { - match *self { - MetaType::Enum(_) | MetaType::Scalar(_) => true, - _ => false, - } + matches!(*self, MetaType::Enum(_) | MetaType::Scalar(_)) } /// Returns true if the type is abstract /// /// Only interfaces and unions are abstract types. pub fn is_abstract(&self) -> bool { - match *self { - MetaType::Interface(_) | MetaType::Union(_) => true, - _ => false, - } + matches!(*self, MetaType::Interface(_) | MetaType::Union(_)) } /// Returns true if the type can be used in input positions, e.g. arguments or variables /// /// Only scalars, enums, and input objects are input types. pub fn is_input(&self) -> bool { - match *self { - MetaType::Scalar(_) | MetaType::Enum(_) | MetaType::InputObject(_) => true, - _ => false, - } + matches!(*self, MetaType::Scalar(_) | MetaType::Enum(_) | MetaType::InputObject(_)) } /// Returns true if the type is built-in to GraphQL. diff --git a/juniper/src/schema/model.rs b/juniper/src/schema/model.rs index 7be0c616..76853bcf 100644 --- a/juniper/src/schema/model.rs +++ b/juniper/src/schema/model.rs @@ -367,7 +367,7 @@ impl<'a, S> SchemaType<'a, S> { /// Determine if there is an overlap between types. pub fn type_overlap(&self, t1: &MetaType, t2: &MetaType) -> bool { - if (t1 as *const MetaType) == (t2 as *const MetaType) { + if std::ptr::eq(t1, t2) { return true; } @@ -414,7 +414,7 @@ impl<'a, S> SchemaType<'a, S> { ) -> bool { self.possible_types(abstract_type) .into_iter() - .any(|t| (t as *const MetaType) == (possible_type as *const MetaType)) + .any(|t| (std::ptr::eq(t, possible_type))) } /// If the type is a subtype of another type. @@ -483,10 +483,7 @@ impl<'a, S> TypeType<'a, S> { #[inline] pub fn is_non_null(&self) -> bool { - match *self { - TypeType::NonNull(_) => true, - _ => false, - } + matches!(*self, TypeType::NonNull(_)) } } diff --git a/juniper/src/types/name.rs b/juniper/src/types/name.rs index 72b8e04d..eae555d9 100644 --- a/juniper/src/types/name.rs +++ b/juniper/src/types/name.rs @@ -9,11 +9,11 @@ use std::{ // stabilise (https://github.com/rust-lang/rust/issues/39658). fn is_ascii_alphabetic(c: char) -> bool { - c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' + ('a'..='z').contains(&c) || ('A'..='Z').contains(&c) } fn is_ascii_digit(c: char) -> bool { - c >= '0' && c <= '9' + ('0'..='9').contains(&c) } #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/juniper/src/types/nullable.rs b/juniper/src/types/nullable.rs index 9436e842..0e3659fc 100644 --- a/juniper/src/types/nullable.rs +++ b/juniper/src/types/nullable.rs @@ -48,37 +48,25 @@ impl Nullable { /// Returns `true` if the nullable is a `ExplicitNull` value. #[inline] pub fn is_explicit_null(&self) -> bool { - match self { - Self::ExplicitNull => true, - _ => false, - } + matches!(self, Self::ExplicitNull) } /// Returns `true` if the nullable is a `ImplicitNull` value. #[inline] pub fn is_implicit_null(&self) -> bool { - match self { - Self::ImplicitNull => true, - _ => false, - } + matches!(self, Self::ImplicitNull) } /// Returns `true` if the nullable is a `Some` value. #[inline] pub fn is_some(&self) -> bool { - match self { - Self::Some(_) => true, - _ => false, - } + matches!(self, Self::Some(_)) } /// Returns `true` if the nullable is not a `Some` value. #[inline] pub fn is_null(&self) -> bool { - match self { - Self::Some(_) => false, - _ => true, - } + !matches!(self, Self::Some(_)) } /// Converts from `&mut Nullable` to `Nullable<&mut T>`. diff --git a/juniper/src/util.rs b/juniper/src/util.rs index 6642b0ab..08f51493 100644 --- a/juniper/src/util.rs +++ b/juniper/src/util.rs @@ -9,9 +9,13 @@ pub fn to_camel_case(s: &'_ str) -> Cow<'_, str> { // handle '_' to be more friendly with the // _var convention for unused variables - let s_iter = if s.starts_with('_') { &s[1..] } else { s } - .split('_') - .enumerate(); + let s_iter = if let Some(stripped) = s.strip_prefix('_') { + stripped + } else { + s + } + .split('_') + .enumerate(); for (i, part) in s_iter { if i > 0 && part.len() == 1 { diff --git a/juniper/src/validation/rules/overlapping_fields_can_be_merged.rs b/juniper/src/validation/rules/overlapping_fields_can_be_merged.rs index b693ad28..ce42cbd8 100644 --- a/juniper/src/validation/rules/overlapping_fields_can_be_merged.rs +++ b/juniper/src/validation/rules/overlapping_fields_can_be_merged.rs @@ -587,10 +587,8 @@ impl<'a, S: Debug> OverlappingFieldsCanBeMerged<'a, S> { } fn is_object_type(&self, ctx: &ValidatorContext<'a, S>, type_name: Option<&str>) -> bool { - match type_name.and_then(|n| ctx.schema.concrete_type_by_name(n)) { - Some(&MetaType::Object(_)) => true, - _ => false, - } + let meta = type_name.and_then(|n| ctx.schema.concrete_type_by_name(n)); + matches!(meta, Some(&MetaType::Object(_))) } fn get_referenced_fields_and_fragment_names( diff --git a/juniper/src/value/mod.rs b/juniper/src/value/mod.rs index eb6b6259..fab55d7b 100644 --- a/juniper/src/value/mod.rs +++ b/juniper/src/value/mod.rs @@ -89,10 +89,7 @@ impl Value { /// Does this value represent null? pub fn is_null(&self) -> bool { - match *self { - Self::Null => true, - _ => false, - } + matches!(*self, Self::Null) } /// View the underlying scalar value if present diff --git a/juniper_codegen/src/impl_scalar.rs b/juniper_codegen/src/impl_scalar.rs index 74dc6d7e..e022e575 100644 --- a/juniper_codegen/src/impl_scalar.rs +++ b/juniper_codegen/src/impl_scalar.rs @@ -62,10 +62,7 @@ fn get_enum_type(return_type: &Option) -> Option { syn::PathArguments::AngleBracketed(generic_args) => { let generic_type_arg = generic_args.args.iter().find(|generic_type_arg| { - match generic_type_arg { - syn::GenericArgument::Type(_) => true, - _ => false, - } + matches!(generic_type_arg, syn::GenericArgument::Type(_)) }); if let Some(syn::GenericArgument::Type(syn::Type::Path(type_path))) = diff --git a/juniper_graphql_ws/src/lib.rs b/juniper_graphql_ws/src/lib.rs index 32bee011..59834ba3 100644 --- a/juniper_graphql_ws/src/lib.rs +++ b/juniper_graphql_ws/src/lib.rs @@ -97,7 +97,7 @@ enum Reaction { impl Reaction { /// Converts the reaction into a one-item stream. - fn to_stream(self) -> BoxStream<'static, Self> { + fn into_stream(self) -> BoxStream<'static, Self> { stream::once(future::ready(self)).boxed() } } @@ -153,7 +153,7 @@ impl> ConnectionState { msg: ClientMessage, ) -> (Self, BoxStream<'static, Reaction>) { if let ClientMessage::ConnectionTerminate = msg { - return (self, Reaction::EndStream.to_stream()); + return (self, Reaction::EndStream.into_stream()); } match self { @@ -171,7 +171,7 @@ impl> ConnectionState { s = s .chain( Reaction::ServerMessage(ServerMessage::ConnectionKeepAlive) - .to_stream(), + .into_stream(), ) .boxed(); s = s @@ -270,7 +270,7 @@ impl> ConnectionState { // Once the stream ends, send the Complete message. let s = s.chain( Reaction::ServerMessage(ServerMessage::Complete { id }) - .to_stream(), + .into_stream(), ); s.boxed() @@ -306,11 +306,7 @@ impl> ConnectionState { // Try to execute this as a query or mutation. match juniper::execute( ¶ms.start_payload.query, - params - .start_payload - .operation_name - .as_ref() - .map(|s| s.as_str()), + params.start_payload.operation_name.as_deref(), params.schema.root_node(), ¶ms.start_payload.variables, ¶ms.config.context, @@ -322,7 +318,7 @@ impl> ConnectionState { id: id.clone(), payload: DataPayload { data, errors }, }) - .to_stream(); + .into_stream(); } Err(GraphQLError::IsSubscription) => {} Err(e) => { @@ -331,7 +327,7 @@ impl> ConnectionState { // e only references data owned by params. The new ErrorPayload will continue to keep that data alive. payload: unsafe { ErrorPayload::new_unchecked(Box::new(params.clone()), e) }, }) - .to_stream(); + .into_stream(); } } @@ -423,11 +419,7 @@ impl Stream for SubscriptionStart { future: unsafe { juniper::resolve_into_stream( &(*params).start_payload.query, - (*params) - .start_payload - .operation_name - .as_ref() - .map(|s| s.as_str()), + (*params).start_payload.operation_name.as_deref(), (*params).schema.root_node(), &(*params).start_payload.variables, &(*params).config.context, @@ -575,7 +567,7 @@ where message: e.to_string(), }, }) - .to_stream(), + .into_stream(), ); ConnectionSinkState::Ready { state } } diff --git a/juniper_hyper/src/lib.rs b/juniper_hyper/src/lib.rs index b35a44d9..f42bc0f6 100644 --- a/juniper_hyper/src/lib.rs +++ b/juniper_hyper/src/lib.rs @@ -73,7 +73,7 @@ async fn parse_req( } _ => return Err(new_response(StatusCode::METHOD_NOT_ALLOWED)), } - .map_err(|e| render_error(e)) + .map_err(render_error) } fn parse_get_req( diff --git a/juniper_iron/src/lib.rs b/juniper_iron/src/lib.rs index 91c60041..b58bcd7a 100644 --- a/juniper_iron/src/lib.rs +++ b/juniper_iron/src/lib.rs @@ -230,7 +230,7 @@ where .map_err(GraphQLIronError::Url)?; let query = parse_url_param(url_query.remove("query"))? - .ok_or_else(|| GraphQLIronError::InvalidData("No query provided"))?; + .ok_or(GraphQLIronError::InvalidData("No query provided"))?; let operation_name = parse_url_param(url_query.remove("operationName"))?; let variables = parse_variable_param(url_query.remove("variables"))?;