Skip to content

Commit 3bb8c1e

Browse files
author
Vincent Prouillet
committed
Clean up
1 parent c975069 commit 3bb8c1e

File tree

7 files changed

+48
-71
lines changed

7 files changed

+48
-71
lines changed

src/format.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,15 @@ pub(crate) fn format_directives(dirs: &[Directive], f: &mut Formatter) {
136136
dir.display(f);
137137
}
138138
}
139+
140+
macro_rules! impl_display {
141+
($( $typ: ident, )+) => {
142+
$(
143+
impl fmt::Display for $typ {
144+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
145+
f.write_str(&to_string(self))
146+
}
147+
}
148+
)+
149+
};
150+
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ extern crate combine;
9999

100100

101101
mod common;
102+
#[macro_use]
102103
mod format;
103104
mod position;
104105
mod tokenizer;

src/query/format.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -326,17 +326,7 @@ impl Displayable for Directive {
326326
}
327327
}
328328

329-
macro_rules! impl_display {
330-
($( $typ: ident, )+) => {
331-
$(
332-
impl fmt::Display for $typ {
333-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
334-
f.write_str(&to_string(self))
335-
}
336-
}
337-
)+
338-
};
339-
}
329+
340330
impl_display!(
341331
Document,
342332
Definition,

src/schema/ast.rs

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ pub enum DirectiveLocation {
188188
FragmentDefinition,
189189
FragmentSpread,
190190
InlineFragment,
191+
191192
// type_system
192193
Schema,
193194
Scalar,
@@ -212,7 +213,7 @@ pub struct DirectiveDefinition {
212213
}
213214

214215
impl DirectiveLocation {
215-
/// Returns graphql syntax compatible name of the directive
216+
/// Returns GraphQL syntax compatible name of the directive
216217
pub fn as_str(&self) -> &'static str {
217218
use self::DirectiveLocation::*;
218219
match *self {
@@ -236,53 +237,38 @@ impl DirectiveLocation {
236237
InputFieldDefinition => "INPUT_FIELD_DEFINITION",
237238
}
238239
}
239-
/// Returns true if this location is for queries (execution)
240+
241+
/// Returns `true` if this location is for queries (execution)
240242
pub fn is_query(&self) -> bool {
241243
use self::DirectiveLocation::*;
242244
match *self {
243-
Query => true,
244-
Mutation => true,
245-
Subscription => true,
246-
Field => true,
247-
FragmentDefinition => true,
248-
FragmentSpread => true,
249-
InlineFragment => true,
250-
Schema => false,
251-
Scalar => false,
252-
Object => false,
253-
FieldDefinition => false,
254-
ArgumentDefinition => false,
255-
Interface => false,
256-
Union => false,
257-
Enum => false,
258-
EnumValue => false,
259-
InputObject => false,
260-
InputFieldDefinition => false,
245+
Query
246+
| Mutation
247+
| Subscription
248+
| Field
249+
| FragmentDefinition
250+
| FragmentSpread
251+
| InlineFragment
252+
=> true,
253+
254+
Schema
255+
| Scalar
256+
| Object
257+
| FieldDefinition
258+
| ArgumentDefinition
259+
| Interface
260+
| Union
261+
| Enum
262+
| EnumValue
263+
| InputObject
264+
| InputFieldDefinition
265+
=> false,
261266
}
262267
}
263-
/// Returns true if this location is for schema
268+
269+
/// Returns `true` if this location is for schema
264270
pub fn is_schema(&self) -> bool {
265-
use self::DirectiveLocation::*;
266-
match *self {
267-
Query => false,
268-
Mutation => false,
269-
Subscription => false,
270-
Field => false,
271-
FragmentDefinition => false,
272-
FragmentSpread => false,
273-
InlineFragment => false,
274-
Schema => true,
275-
Scalar => true,
276-
Object => true,
277-
FieldDefinition => true,
278-
ArgumentDefinition => true,
279-
Interface => true,
280-
Union => true,
281-
Enum => true,
282-
EnumValue => true,
283-
InputObject => true,
284-
InputFieldDefinition => true,
285-
}
271+
!self.is_query()
286272
}
287273
}
288274

@@ -317,6 +303,7 @@ impl FromStr for DirectiveLocation {
317303
"INPUT_FIELD_DEFINITION" => InputFieldDefinition,
318304
_ => return Err(InvalidDirectiveLocation),
319305
};
320-
return Ok(val);
306+
307+
Ok(val)
321308
}
322309
}

src/schema/format.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -388,20 +388,6 @@ impl Displayable for DirectiveDefinition {
388388
}
389389
}
390390

391-
392-
393-
macro_rules! impl_display {
394-
($( $typ: ident, )+) => {
395-
$(
396-
impl fmt::Display for $typ {
397-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
398-
f.write_str(&to_string(self))
399-
}
400-
}
401-
)+
402-
};
403-
}
404-
405391
impl_display!(
406392
Document,
407393
Definition,

src/tokenizer.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,15 @@ fn check_dec(value: &str) -> bool {
9595
}
9696

9797
fn check_exp(value: &str) -> bool {
98-
if value.len() == 0 {
98+
if value.is_empty() {
9999
return false;
100100
}
101101
let first = value.chars().next().unwrap();
102102
if first != '-' && first != '+' && (first <= '0' || first >= '9') {
103103
return false;
104104
}
105-
return value[1..].chars().all(|x| x >= '0' && x <= '9');
105+
106+
value[1..].chars().all(|x| x >= '0' && x <= '9')
106107
}
107108

108109
fn check_float(value: &str, exponent: Option<usize>, real: Option<usize>)

tests/query_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn test_error(filename: &str) {
1414
let mut iter = buf.splitn(2, "\n---\n");
1515
let graphql = iter.next().unwrap();
1616
let expected = iter.next().expect("file should contain error message");
17-
let err = parse_query(&graphql).unwrap_err();
17+
let err = parse_query(graphql).unwrap_err();
1818
assert_eq!(err.to_string(), expected);
1919
}
2020

0 commit comments

Comments
 (0)