Skip to content

Commit

Permalink
Fix cargo clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Atul9 committed Jan 28, 2018
1 parent a7d843e commit 438d56a
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 26 deletions.
6 changes: 3 additions & 3 deletions juniper/src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,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: 6 additions & 6 deletions juniper/src/integrations/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ impl<'de> de::Deserialize<'de> for InputValue {
where
E: de::Error,
{
if value >= i32::min_value() as i64 && value <= i32::max_value() as i64 {
Ok(InputValue::int(value as i32))
if value >= i64::from(i32::min_value()) && value <= i64::from(i32::max_value()) {
Ok(InputValue::int(i32::from(value)))
} else {
Err(E::custom(format!("integer out of range")))
}
Expand All @@ -87,8 +87,8 @@ impl<'de> de::Deserialize<'de> for InputValue {
where
E: de::Error,
{
if value <= i32::max_value() as u64 {
self.visit_i64(value as i64)
if value <= u64::from(i32::max_value()) {
self.visit_i64(i64::from(value))
} else {
Err(E::custom(format!("integer out of range")))
}
Expand Down Expand Up @@ -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 Down Expand Up @@ -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/macros/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)* );
};
}
12 changes: 7 additions & 5 deletions juniper/src/parser/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ impl<'a> Lexer<'a> {
}

let mantissa = frac_part
.map(|f| f as f64)
.map(|f| f64::from(f))
.map(|frac| {
if frac > 0f64 {
frac / 10f64.powf(frac.log10().floor() + 1f64)
Expand All @@ -400,16 +400,18 @@ impl<'a> Lexer<'a> {
})
.map(|m| if int_part < 0 { -m } else { m });

let exp = exp_part.map(|e| e as f64).map(|e| 10f64.powf(e));
let exp = exp_part.map(|e| f64::from(e)).map(|e| 10f64.powf(e));

Ok(Spanning::start_end(
&start_pos,
&self.position,
match (mantissa, exp) {
(None, None) => Token::Int(int_part),
(None, Some(exp)) => Token::Float((int_part as f64) * exp),
(Some(mantissa), None) => Token::Float((int_part as f64) + mantissa),
(Some(mantissa), Some(exp)) => Token::Float(((int_part as f64) + mantissa) * exp),
(None, Some(exp)) => Token::Float((f64::from(int_part)) * exp),
(Some(mantissa), None) => Token::Float((f64::from(int_part)) + mantissa),
(Some(mantissa), Some(exp)) => {
Token::Float(((f64::from(int_part)) + mantissa) * exp)
}
},
))
}
Expand Down
2 changes: 1 addition & 1 deletion juniper/src/schema/meta.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Types used to describe a GraphQL schema
//! Types used to describe a `GraphQL` schema
use std::borrow::Cow;
use std::fmt;
Expand Down
2 changes: 1 addition & 1 deletion juniper/src/types/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ where

let sub_exec = executor.field_sub_executor(
response_name,
&f.name.item,
f.name.item,
start_pos.clone(),
f.selection_set.as_ref().map(|v| &v[..]),
);
Expand Down
2 changes: 1 addition & 1 deletion juniper/src/types/scalars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ graphql_scalar!(f64 as "Float" {

from_input_value(v: &InputValue) -> Option<f64> {
match *v {
InputValue::Int(i) => Some(i as f64),
InputValue::Int(i) => Some(f64::from(i)),
InputValue::Float(f) => Some(f),
_ => None,
}
Expand Down
2 changes: 1 addition & 1 deletion juniper_iron/examples/iron_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn main() {
chain.link_before(logger_before);
chain.link_after(logger_after);

let host = env::var("LISTEN").unwrap_or("0.0.0.0:8080".to_owned());
let host = env::var("LISTEN").unwrap_or_else(|_| "0.0.0.0:8080".to_owned());
println!("GraphQL server started on {}", host);
Iron::new(chain).http(host.as_str()).unwrap();
}
14 changes: 7 additions & 7 deletions juniper_iron/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ use serde_json::error::Error as SerdeError;
use juniper::{GraphQLType, InputValue, RootNode};
use juniper::http;

/// Handler that executes GraphQL queries in the given schema
/// Handler that executes `GraphQL` queries in the given schema
///
/// The handler responds to GET requests and POST requests only. In GET
/// requests, the query should be supplied in the `query` URL parameter, e.g.
Expand All @@ -146,7 +146,7 @@ where
root_node: RootNode<'a, Query, Mutation>,
}

/// Handler that renders GraphiQL - a graphical query editor interface
/// Handler that renders `GraphiQL` - a graphical query editor interface
pub struct GraphiQLHandler {
graphql_url: String,
}
Expand Down Expand Up @@ -201,7 +201,7 @@ where

fn handle_get(&self, req: &mut Request) -> IronResult<http::GraphQLRequest> {
let url_query_string = req.get_mut::<UrlEncodedQuery>()
.map_err(|e| GraphQLIronError::Url(e))?;
.map_err(GraphQLIronError::Url)?;

let input_query = parse_url_param(url_query_string.remove("query"))?
.ok_or_else(|| GraphQLIronError::InvalidData("No query provided"))?;
Expand All @@ -221,7 +221,7 @@ where

Ok(
serde_json::from_str::<http::GraphQLRequest>(request_payload.as_str())
.map_err(|err| GraphQLIronError::Serde(err))?,
.map_err(GraphQLIronError::Serde)?,
)
}

Expand Down Expand Up @@ -265,7 +265,7 @@ where
let graphql_request = match req.method {
method::Get => self.handle_get(&mut req)?,
method::Post => self.handle_post(&mut req)?,
_ => return Ok(Response::with((status::MethodNotAllowed))),
_ => return Ok(Response::with(status::MethodNotAllowed)),
};

self.execute(&context, graphql_request)
Expand Down Expand Up @@ -296,7 +296,7 @@ impl fmt::Display for GraphQLIronError {
match *self {
GraphQLIronError::Serde(ref err) => fmt::Display::fmt(err, &mut f),
GraphQLIronError::Url(ref err) => fmt::Display::fmt(err, &mut f),
GraphQLIronError::InvalidData(ref err) => fmt::Display::fmt(err, &mut f),
GraphQLIronError::InvalidData(err) => fmt::Display::fmt(err, &mut f),
}
}
}
Expand All @@ -306,7 +306,7 @@ impl Error for GraphQLIronError {
match *self {
GraphQLIronError::Serde(ref err) => err.description(),
GraphQLIronError::Url(ref err) => err.description(),
GraphQLIronError::InvalidData(ref err) => err,
GraphQLIronError::InvalidData(err) => err,
}
}

Expand Down

0 comments on commit 438d56a

Please sign in to comment.