From deeedf11a6d1e3d544da358aa2a29b39265d0d78 Mon Sep 17 00:00:00 2001 From: Sunli Date: Fri, 7 May 2021 10:14:05 +0800 Subject: [PATCH] Clippy clean --- parser/src/pos.rs | 2 +- src/model/schema.rs | 18 ++++++++---------- src/registry/mod.rs | 8 +++----- src/types/connection/edge.rs | 2 +- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/parser/src/pos.rs b/parser/src/pos.rs index 1acff47e..3f37e3e7 100644 --- a/parser/src/pos.rs +++ b/parser/src/pos.rs @@ -51,7 +51,7 @@ impl Positioned { /// Create a new positioned node from the node and its position. #[must_use] pub const fn new(node: T, pos: Pos) -> Positioned { - Positioned { node, pos } + Positioned { pos, node } } /// Get the inner node. diff --git a/src/model/schema.rs b/src/model/schema.rs index 893c0323..a5323cc6 100644 --- a/src/model/schema.rs +++ b/src/model/schema.rs @@ -38,21 +38,19 @@ impl<'a> __Schema<'a> { /// If this server supports mutation, the type that mutation operations will be rooted at. #[inline] async fn mutation_type(&self) -> Option<__Type<'a>> { - if let Some(ty) = &self.registry.mutation_type { - Some(__Type::new_simple(self.registry, &self.registry.types[ty])) - } else { - None - } + self.registry + .mutation_type + .as_ref() + .map(|ty| __Type::new_simple(self.registry, &self.registry.types[ty])) } /// If this server support subscription, the type that subscription operations will be rooted at. #[inline] async fn subscription_type(&self) -> Option<__Type<'a>> { - if let Some(ty) = &self.registry.subscription_type { - Some(__Type::new_simple(self.registry, &self.registry.types[ty])) - } else { - None - } + self.registry + .subscription_type + .as_ref() + .map(|ty| __Type::new_simple(self.registry, &self.registry.types[ty])) } /// A list of all directives supported by this server. diff --git a/src/registry/mod.rs b/src/registry/mod.rs index a8d1a7ff..0c8c9121 100644 --- a/src/registry/mod.rs +++ b/src/registry/mod.rs @@ -17,11 +17,9 @@ use crate::{model, Any, Context, Positioned, ServerResult, Type, Value, VisitorC pub use cache_control::CacheControl; fn strip_brackets(type_name: &str) -> Option<&str> { - if let Some(rest) = type_name.strip_prefix('[') { - Some(&rest[..rest.len() - 1]) - } else { - None - } + type_name + .strip_prefix('[') + .map(|rest| &rest[..rest.len() - 1]) } #[derive(Clone, Copy, PartialEq, Debug)] diff --git a/src/types/connection/edge.rs b/src/types/connection/edge.rs index aba6f2df..f6c893bb 100644 --- a/src/types/connection/edge.rs +++ b/src/types/connection/edge.rs @@ -23,8 +23,8 @@ impl Edge { pub fn with_additional_fields(cursor: C, node: T, additional_fields: E) -> Self { Self { cursor, - additional_fields, node, + additional_fields, } } }