Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up clippy warnings remove try! #135

Merged
merged 5 commits into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions juniper/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,25 +432,25 @@ impl fmt::Display for InputValue {
InputValue::Enum(ref v) => write!(f, "{}", v),
InputValue::Variable(ref v) => write!(f, "${}", v),
InputValue::List(ref v) => {
try!(write!(f, "["));
write!(f, "[")?;

for (i, spanning) in v.iter().enumerate() {
try!(spanning.item.fmt(f));
spanning.item.fmt(f)?;
if i < v.len() - 1 {
try!(write!(f, ", "));
write!(f, ", ")?;
}
}

write!(f, "]")
}
InputValue::Object(ref o) => {
try!(write!(f, "{{"));
write!(f, "{{")?;

for (i, &(ref k, ref v)) in o.iter().enumerate() {
try!(write!(f, "{}: ", k.item));
try!(v.item.fmt(f));
write!(f, "{}: ", k.item)?;
v.item.fmt(f)?;
if i < o.len() - 1 {
try!(write!(f, ", "));
write!(f, ", ")?;
}
}

Expand Down
9 changes: 5 additions & 4 deletions juniper/src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ impl<'a, T: GraphQLType, C> IntoResolvable<'a, T, C> for FieldResult<(&'a T::Con
}

impl<'a, T: GraphQLType, C> IntoResolvable<'a, Option<T>, C>
for FieldResult<Option<(&'a T::Context, T)>> {
for FieldResult<Option<(&'a T::Context, T)>>
{
fn into(self, _: &'a C) -> FieldResult<Option<(&'a T::Context, Option<T>)>> {
self.map(|o| o.map(|(ctx, v)| (ctx, Some(v))))
}
Expand All @@ -229,20 +230,20 @@ impl<'a, T: GraphQLType, C> IntoResolvable<'a, Option<T>, C>
/// Conversion trait for context types
///
/// Used to support different context types for different parts of an
/// application. By making each GraphQL type only aware of as much
/// application. By making each `GraphQL` type only aware of as much
/// context as it needs to, isolation and robustness can be
/// improved. Implement this trait if you have contexts that can
/// generally be converted between each other.
///
/// The empty tuple `()` can be converted into from any context type,
/// making it suitable for GraphQL that don't need _any_ context to
/// making it suitable for `GraphQL` that don't need _any_ context to
/// work, e.g. scalars or enums.
pub trait FromContext<T> {
/// Perform the conversion
fn from(value: &T) -> &Self;
}

/// Marker trait for types that can act as context objects for GraphQL types.
/// Marker trait for types that can act as context objects for `GraphQL` types.
pub trait Context {}

impl<'a, C: Context> Context for &'a C {}
Expand Down
12 changes: 8 additions & 4 deletions juniper/src/executor_tests/introspection/input_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,19 @@ pub struct NamedPublic {
#[derive(GraphQLInputObject, Debug)]
#[graphql(_internal)]
struct FieldDescription {
#[graphql(description = "The first field")] field_one: String,
#[graphql(description = "The second field")] field_two: String,
#[graphql(description = "The first field")]
field_one: String,
#[graphql(description = "The second field")]
field_two: String,
}

#[derive(GraphQLInputObject, Debug)]
#[graphql(_internal)]
struct FieldWithDefaults {
#[graphql(default = "123")] field_one: i32,
#[graphql(default = "456", description = "The second field")] field_two: i32,
#[graphql(default = "123")]
field_one: i32,
#[graphql(default = "456", description = "The second field")]
field_two: i32,
}

graphql_object!(Root: () |&self| {
Expand Down
3 changes: 2 additions & 1 deletion juniper/src/executor_tests/variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ struct ExampleInputObject {
#[derive(GraphQLInputObject, Debug)]
#[graphql(_internal)]
struct InputWithDefaults {
#[graphql(default = "123")] a: i32,
#[graphql(default = "123")]
a: i32,
}

graphql_object!(TestType: () |&self| {
Expand Down
19 changes: 10 additions & 9 deletions juniper/src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use executor::ExecutionError;
#[derive(Deserialize, Clone, Serialize, PartialEq, Debug)]
pub struct GraphQLRequest {
query: String,
#[serde(rename = "operationName")] operation_name: Option<String>,
#[serde(rename = "operationName")]
operation_name: Option<String>,
variables: Option<InputValue>,
}

Expand Down Expand Up @@ -101,22 +102,22 @@ impl<'a> ser::Serialize for GraphQLResponse<'a> {
{
match self.0 {
Ok((ref res, ref err)) => {
let mut map = try!(serializer.serialize_map(None));
let mut map = serializer.serialize_map(None)?;

try!(map.serialize_key("data"));
try!(map.serialize_value(res));
map.serialize_key("data")?;
map.serialize_value(res)?;

if !err.is_empty() {
try!(map.serialize_key("errors"));
try!(map.serialize_value(err));
map.serialize_key("errors")?;
map.serialize_value(err)?;
}

map.end()
}
Err(ref err) => {
let mut map = try!(serializer.serialize_map(Some(1)));
try!(map.serialize_key("errors"));
try!(map.serialize_value(err));
let mut map = serializer.serialize_map(Some(1))?;
map.serialize_key("errors")?;
map.serialize_value(err)?;
map.end()
}
}
Expand Down
62 changes: 31 additions & 31 deletions juniper/src/integrations/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ impl ser::Serialize for ExecutionError {
where
S: ser::Serializer,
{
let mut map = try!(serializer.serialize_map(Some(4)));
let mut map = serializer.serialize_map(Some(4))?;

try!(map.serialize_key("message"));
try!(map.serialize_value(self.error().message()));
map.serialize_key("message")?;
map.serialize_value(self.error().message())?;

let locations = vec![self.location()];
try!(map.serialize_key("locations"));
try!(map.serialize_value(&locations));
map.serialize_key("locations")?;
map.serialize_value(&locations)?;

try!(map.serialize_key("path"));
try!(map.serialize_value(self.path()));
map.serialize_key("path")?;
map.serialize_value(self.path())?;

if !self.error().data().is_null() {
try!(map.serialize_key("data"));
try!(map.serialize_value(self.error().data()));
map.serialize_key("data")?;
map.serialize_value(self.error().data())?;
}

map.end()
Expand Down Expand Up @@ -76,10 +76,10 @@ impl<'de> de::Deserialize<'de> for InputValue {
where
E: de::Error,
{
if value >= i32::min_value() as i64 && value <= i32::max_value() as i64 {
if value >= i64::from(i32::min_value()) && value <= i64::from(i32::max_value()) {
Ok(InputValue::int(value as i32))
} else {
Err(E::custom(format!("integer out of range")))
Err(E::custom("integer out of range"))
}
}

Expand All @@ -90,7 +90,7 @@ impl<'de> de::Deserialize<'de> for InputValue {
if value <= i32::max_value() as u64 {
self.visit_i64(value as i64)
} else {
Err(E::custom(format!("integer out of range")))
Err(E::custom("integer out of range"))
}
}

Expand Down Expand Up @@ -123,7 +123,7 @@ impl<'de> de::Deserialize<'de> for InputValue {
{
let mut values = Vec::new();

while let Some(el) = try!(visitor.next_element()) {
while let Some(el) = visitor.next_element()? {
values.push(el);
}

Expand All @@ -136,7 +136,7 @@ impl<'de> de::Deserialize<'de> for InputValue {
{
let mut values: IndexMap<String, InputValue> = IndexMap::new();

while let Some((key, value)) = try!(visitor.next_entry()) {
while let Some((key, value)) = visitor.next_entry()? {
values.insert(key, value);
}

Expand All @@ -155,7 +155,7 @@ impl ser::Serialize for InputValue {
{
match *self {
InputValue::Null | InputValue::Variable(_) => serializer.serialize_unit(),
InputValue::Int(v) => serializer.serialize_i64(v as i64),
InputValue::Int(v) => serializer.serialize_i64(i64::from(v)),
InputValue::Float(v) => serializer.serialize_f64(v),
InputValue::String(ref v) | InputValue::Enum(ref v) => serializer.serialize_str(v),
InputValue::Boolean(v) => serializer.serialize_bool(v),
Expand All @@ -176,13 +176,13 @@ impl ser::Serialize for RuleError {
where
S: ser::Serializer,
{
let mut map = try!(serializer.serialize_map(Some(2)));
let mut map = serializer.serialize_map(Some(2))?;

try!(map.serialize_key("message"));
try!(map.serialize_value(self.message()));
map.serialize_key("message")?;
map.serialize_value(self.message())?;

try!(map.serialize_key("locations"));
try!(map.serialize_value(self.locations()));
map.serialize_key("locations")?;
map.serialize_value(self.locations())?;

map.end()
}
Expand All @@ -193,15 +193,15 @@ impl ser::Serialize for SourcePosition {
where
S: ser::Serializer,
{
let mut map = try!(serializer.serialize_map(Some(2)));
let mut map = serializer.serialize_map(Some(2))?;

let line = self.line() + 1;
try!(map.serialize_key("line"));
try!(map.serialize_value(&line));
map.serialize_key("line")?;
map.serialize_value(&line)?;

let column = self.column() + 1;
try!(map.serialize_key("column"));
try!(map.serialize_value(&column));
map.serialize_key("column")?;
map.serialize_value(&column)?;

map.end()
}
Expand All @@ -212,20 +212,20 @@ impl<'a> ser::Serialize for Spanning<ParseError<'a>> {
where
S: ser::Serializer,
{
let mut map = try!(serializer.serialize_map(Some(2)));
let mut map = serializer.serialize_map(Some(2))?;

let message = format!("{}", self.item);
try!(map.serialize_key("message"));
try!(map.serialize_value(&message));
map.serialize_key("message")?;
map.serialize_value(&message)?;

let mut location = IndexMap::new();
location.insert("line".to_owned(), self.start.line() + 1);
location.insert("column".to_owned(), self.start.column() + 1);

let locations = vec![location];

try!(map.serialize_key("locations"));
try!(map.serialize_value(&locations));
map.serialize_key("locations")?;
map.serialize_value(&locations)?;

map.end()
}
Expand All @@ -238,7 +238,7 @@ impl ser::Serialize for Value {
{
match *self {
Value::Null => serializer.serialize_unit(),
Value::Int(v) => serializer.serialize_i64(v as i64),
Value::Int(v) => serializer.serialize_i64(i64::from(v)),
Value::Float(v) => serializer.serialize_f64(v),
Value::String(ref v) => serializer.serialize_str(v),
Value::Boolean(v) => serializer.serialize_bool(v),
Expand Down
2 changes: 1 addition & 1 deletion juniper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ where
QueryT: GraphQLType<Context = CtxT>,
MutationT: GraphQLType<Context = CtxT>,
{
let document = try!(parse_document_source(document_source));
let document = parse_document_source(document_source)?;

{
let errors = validate_input_values(variables, &document, &root_node.schema);
Expand Down
6 changes: 3 additions & 3 deletions juniper/src/macros/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ macro_rules! graphql_scalar {
// and body for the from() method on FromInputValue.
(
@generate,
( $name:ty, $outname:tt, $descr:tt ),
( $name:ty, $outname:expr, $descr:tt ),
(
( $resolve_selfvar:ident, $resolve_body:block ),
( $fiv_arg:ident, $fiv_result:ty, $fiv_body:block )
Expand Down Expand Up @@ -135,7 +135,7 @@ macro_rules! graphql_scalar {
// description: <description>
(
@parse,
( $name:ty, $outname:tt, $_ignored:tt ),
( $name:ty, $outname:expr, $_ignored:tt ),
$acc:tt,
description: $descr:tt $($rest:tt)*
) => {
Expand All @@ -151,6 +151,6 @@ macro_rules! graphql_scalar {
// Entry point
// RustName { ... }
( $name:ty { $( $items:tt )* }) => {
graphql_scalar!( @parse, ( $name, (stringify!($name)), None ), ( None, None ), $($items)* );
graphql_scalar!( @parse, ( $name, stringify!($name), None ), ( None, None ), $($items)* );
};
}
Loading