Skip to content

Commit 82f9086

Browse files
authored
Merge pull request #178 from h-michael/clippy
Fix clippy warning
2 parents 2c3c83a + 5a3d5f3 commit 82f9086

File tree

10 files changed

+21
-24
lines changed

10 files changed

+21
-24
lines changed

graphql_client/examples/github/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct Env {
4242
}
4343

4444
fn parse_repo_name(repo_name: &str) -> Result<(&str, &str), failure::Error> {
45-
let mut parts = repo_name.split("/");
45+
let mut parts = repo_name.split('/');
4646
match (parts.next(), parts.next()) {
4747
(Some(owner), Some(name)) => Ok((owner, name)),
4848
_ => Err(format_err!("wrong format for the repository name param (we expect something like facebook/graphql)"))

graphql_client_cli/src/generate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ pub fn generate_code(
99
schema_path: PathBuf,
1010
selected_operation: String,
1111
additional_derives: Option<String>,
12-
deprecation_strategy: Option<String>,
12+
deprecation_strategy: &Option<String>,
1313
no_formatting: bool,
14-
output: PathBuf,
14+
output: &PathBuf,
1515
) -> Result<(), failure::Error> {
1616
let deprecation_strategy = deprecation_strategy.as_ref().map(|s| s.as_str());
1717
let deprecation_strategy = match deprecation_strategy {

graphql_client_cli/src/introspect_schema.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ pub fn introspect_schema(
4949
}
5050

5151
let json: serde_json::Value = res.json()?;
52-
Ok(serde_json::to_writer_pretty(out, &json)?)
52+
serde_json::to_writer_pretty(out, &json)?;
53+
Ok(())
5354
}
5455

5556
fn construct_headers() -> HeaderMap {

graphql_client_cli/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ fn main() -> Result<(), failure::Error> {
8383
schema_path,
8484
selected_operation,
8585
additional_derives,
86-
deprecation_strategy,
86+
&deprecation_strategy,
8787
no_formatting,
88-
output,
88+
&output,
8989
),
9090
}
9191
}

graphql_client_codegen/src/codegen.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@ use selection::Selection;
1212
pub(crate) fn select_operation(query: &query::Document, struct_name: &str) -> Option<Operation> {
1313
let mut operations: Vec<Operation> = Vec::new();
1414

15-
for definition in query.definitions.iter() {
16-
match definition {
17-
query::Definition::Operation(op) => {
18-
operations.push(op.into());
19-
}
20-
_ => (),
15+
for definition in &query.definitions {
16+
if let query::Definition::Operation(op) = definition {
17+
operations.push(op.into());
2118
}
2219
}
2320

graphql_client_codegen/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ pub fn generate_module_token_stream(
8484
let response_derives = options.additional_derives;
8585

8686
// The user can determine what to do about deprecations.
87-
let deprecation_strategy = options
88-
.deprecation_strategy
89-
.unwrap_or(deprecation::DeprecationStrategy::default());
87+
let deprecation_strategy = options.deprecation_strategy.unwrap_or_default();
9088

9189
// We need to qualify the query with the path to the crate it is part of
9290
let (query_string, query) = {

graphql_client_codegen/src/query.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ impl QueryContext {
3131
}
3232

3333
pub(crate) fn require(&self, typename_: &str) {
34-
self.fragments
35-
.get(typename_)
36-
.map(|fragment| fragment.is_required.set(true));
34+
if let Some(fragment) = self.fragments.get(typename_) {
35+
fragment.is_required.set(true)
36+
}
3737
}
3838

3939
/// For testing only. creates an empty QueryContext with an empty Schema.
@@ -121,7 +121,7 @@ impl QueryContext {
121121
&& !derive.to_string().contains("Deserialize")
122122
}).collect();
123123

124-
if enum_derives.len() > 0 {
124+
if !enum_derives.is_empty() {
125125
quote! {
126126
#[derive( #(#enum_derives),* )]
127127
}

graphql_client_codegen/src/schema.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl ::std::convert::From<::introspection_response::IntrospectionResponse> for S
235235
name.clone(),
236236
Scalar {
237237
name,
238-
description: ty.description.as_ref().map(|d| d.clone()),
238+
description: ty.description.as_ref().cloned(),
239239
is_required: false.into(),
240240
},
241241
);
@@ -262,7 +262,7 @@ impl ::std::convert::From<::introspection_response::IntrospectionResponse> for S
262262
for implementing in ty
263263
.interfaces
264264
.clone()
265-
.unwrap_or_else(|| Vec::new())
265+
.unwrap_or_else(Vec::new)
266266
.into_iter()
267267
.filter_map(|t| t)
268268
.map(|t| t.type_ref.name)

graphql_client_codegen/src/unions.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ enum UnionError {
2525
MissingTypename { union_name: String },
2626
}
2727

28+
type UnionVariantResult = Result<(Vec<TokenStream>, Vec<TokenStream>, Vec<String>), failure::Error>;
29+
2830
pub(crate) fn union_variants(
2931
selection: &Selection,
3032
query_context: &QueryContext,
3133
prefix: &str,
32-
) -> Result<(Vec<TokenStream>, Vec<TokenStream>, Vec<String>), failure::Error> {
34+
) -> UnionVariantResult {
3335
let mut children_definitions = Vec::new();
3436
let mut used_variants = Vec::with_capacity(selection.0.len());
3537

graphql_query_derive/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ fn build_query_and_schema_path(
4040
fn build_graphql_client_derive_options(input: &syn::DeriveInput) -> GraphQLClientDeriveOptions {
4141
let response_derives = attributes::extract_attr(input, "response_derives").ok();
4242
// The user can determine what to do about deprecations.
43-
let deprecation_strategy = deprecation::extract_deprecation_strategy(input)
44-
.unwrap_or(deprecation::DeprecationStrategy::default());
43+
let deprecation_strategy = deprecation::extract_deprecation_strategy(input).unwrap_or_default();
4544

4645
GraphQLClientDeriveOptions {
4746
struct_name: input.ident.to_string(),

0 commit comments

Comments
 (0)