Rename ToInputValue::to to to_input_value()

This commit is contained in:
theduke 2017-08-29 04:48:11 +02:00 committed by theduke
parent 164aa29fdc
commit 0372de84d5
13 changed files with 28 additions and 28 deletions

View file

@ -160,7 +160,7 @@ pub trait FromInputValue: Sized {
/// Losslessly clones a Rust data type into an InputValue. /// Losslessly clones a Rust data type into an InputValue.
pub trait ToInputValue: Sized { pub trait ToInputValue: Sized {
/// Performs the conversion. /// Performs the conversion.
fn to(&self) -> InputValue; fn to_input_value(&self) -> InputValue;
} }
impl<'a> Type<'a> { impl<'a> Type<'a> {

View file

@ -485,7 +485,7 @@ impl<'r> Registry<'r> {
where where
T: GraphQLType + ToInputValue + FromInputValue, T: GraphQLType + ToInputValue + FromInputValue,
{ {
Argument::new(name, self.get_type::<Option<T>>(info)).default_value(value.to()) Argument::new(name, self.get_type::<Option<T>>(info)).default_value(value.to_input_value())
} }
fn insert_placeholder(&mut self, name: Name, of_type: Type<'r>) { fn insert_placeholder(&mut self, name: Name, of_type: Type<'r>) {

View file

@ -105,7 +105,7 @@ macro_rules! graphql_enum {
} }
impl $crate::ToInputValue for $name { impl $crate::ToInputValue for $name {
fn to(&self) -> $crate::InputValue { fn to_input_value(&self) -> $crate::InputValue {
match *self { match *self {
$( $(
graphql_enum!(@as_pattern, $eval) => graphql_enum!(@as_pattern, $eval) =>

View file

@ -84,7 +84,7 @@ macro_rules! graphql_input_object {
) => { ) => {
$crate::InputValue::object(vec![ $crate::InputValue::object(vec![
$( $(
($crate::to_camel_case(stringify!($field_name)), $selfvar.$field_name.to()) ($crate::to_camel_case(stringify!($field_name)), $selfvar.$field_name.to_input_value())
),* ),*
].into_iter().collect()) ].into_iter().collect())
}; };
@ -232,7 +232,7 @@ macro_rules! graphql_input_object {
} }
impl $crate::ToInputValue for $name { impl $crate::ToInputValue for $name {
fn to(&self) -> $crate::InputValue { fn to_input_value(&self) -> $crate::InputValue {
graphql_input_object!(@generate_to_input_value, $name, self, $fields) graphql_input_object!(@generate_to_input_value, $name, self, $fields)
} }
} }

View file

@ -51,7 +51,7 @@ macro_rules! graphql_scalar {
// string or none). // string or none).
// //
// ( $resolve_selfvar, $resolve_body ): the "self" argument and body for the // ( $resolve_selfvar, $resolve_body ): the "self" argument and body for the
// resolve() method on GraphQLType and the to() method on ToInputValue. // resolve() method on GraphQLType and the to_input_value() method on ToInputValue.
// //
// ( $fiv_arg, $fiv_result, $fiv_body ): the method argument, result type, // ( $fiv_arg, $fiv_result, $fiv_body ): the method argument, result type,
// and body for the from() method on FromInputValue. // and body for the from() method on FromInputValue.
@ -88,8 +88,8 @@ macro_rules! graphql_scalar {
} }
impl $crate::ToInputValue for $name { impl $crate::ToInputValue for $name {
fn to(&$resolve_selfvar) -> $crate::InputValue { fn to_input_value(&$resolve_selfvar) -> $crate::InputValue {
$crate::ToInputValue::to(&$resolve_body) $crate::ToInputValue::to_input_value(&$resolve_body)
} }
} }

View file

@ -52,9 +52,9 @@ impl<T> ToInputValue for Option<T>
where where
T: ToInputValue, T: ToInputValue,
{ {
fn to(&self) -> InputValue { fn to_input_value(&self) -> InputValue {
match *self { match *self {
Some(ref v) => v.to(), Some(ref v) => v.to_input_value(),
None => InputValue::null(), None => InputValue::null(),
} }
} }
@ -117,8 +117,8 @@ impl<T> ToInputValue for Vec<T>
where where
T: ToInputValue, T: ToInputValue,
{ {
fn to(&self) -> InputValue { fn to_input_value(&self) -> InputValue {
InputValue::list(self.iter().map(|v| v.to()).collect()) InputValue::list(self.iter().map(|v| v.to_input_value()).collect())
} }
} }
@ -155,7 +155,7 @@ impl<'a, T> ToInputValue for &'a [T]
where where
T: ToInputValue, T: ToInputValue,
{ {
fn to(&self) -> InputValue { fn to_input_value(&self) -> InputValue {
InputValue::list(self.iter().map(|v| v.to()).collect()) InputValue::list(self.iter().map(|v| v.to_input_value()).collect())
} }
} }

View file

@ -66,8 +66,8 @@ impl<T> ToInputValue for Box<T>
where where
T: ToInputValue, T: ToInputValue,
{ {
fn to(&self) -> InputValue { fn to_input_value(&self) -> InputValue {
(**self).to() (**self).to_input_value()
} }
} }
@ -120,7 +120,7 @@ impl<'a, T> ToInputValue for &'a T
where where
T: ToInputValue, T: ToInputValue,
{ {
fn to(&self) -> InputValue { fn to_input_value(&self) -> InputValue {
(**self).to() (**self).to_input_value()
} }
} }

View file

@ -77,7 +77,7 @@ impl<'a> GraphQLType for &'a str {
} }
impl<'a> ToInputValue for &'a str { impl<'a> ToInputValue for &'a str {
fn to(&self) -> InputValue { fn to_input_value(&self) -> InputValue {
InputValue::string(self) InputValue::string(self)
} }
} }

View file

@ -110,7 +110,7 @@ impl Value {
} }
impl ToInputValue for Value { impl ToInputValue for Value {
fn to(&self) -> InputValue { fn to_input_value(&self) -> InputValue {
match *self { match *self {
Value::Null => InputValue::Null, Value::Null => InputValue::Null,
Value::Int(i) => InputValue::Int(i), Value::Int(i) => InputValue::Int(i),
@ -118,12 +118,12 @@ impl ToInputValue for Value {
Value::String(ref s) => InputValue::String(s.clone()), Value::String(ref s) => InputValue::String(s.clone()),
Value::Boolean(b) => InputValue::Boolean(b), Value::Boolean(b) => InputValue::Boolean(b),
Value::List(ref l) => { Value::List(ref l) => {
InputValue::List(l.iter().map(|x| Spanning::unlocated(x.to())).collect()) InputValue::List(l.iter().map(|x| Spanning::unlocated(x.to_input_value())).collect())
} }
Value::Object(ref o) => InputValue::Object( Value::Object(ref o) => InputValue::Object(
o.iter() o.iter()
.map(|(k, v)| { .map(|(k, v)| {
(Spanning::unlocated(k.clone()), Spanning::unlocated(v.to())) (Spanning::unlocated(k.clone()), Spanning::unlocated(v.to_input_value()))
}) })
.collect(), .collect(),
), ),

View file

@ -181,7 +181,7 @@ pub fn impl_enum(ast: &syn::DeriveInput) -> Tokens {
} }
impl ::juniper::ToInputValue for #ident { impl ::juniper::ToInputValue for #ident {
fn to(&self) -> ::juniper::InputValue { fn to_input_value(&self) -> ::juniper::InputValue {
match self { match self {
#(#to_inputs)* #(#to_inputs)*
} }

View file

@ -178,7 +178,7 @@ pub fn impl_input_object(ast: &syn::DeriveInput) -> Tokens {
// Build to_input clause. // Build to_input clause.
let to_input = quote!{ let to_input = quote!{
(#name, self.#field_ident.to()), (#name, self.#field_ident.to_input_value()),
}; };
to_inputs.push(to_input); to_inputs.push(to_input);
} }
@ -217,7 +217,7 @@ pub fn impl_input_object(ast: &syn::DeriveInput) -> Tokens {
} }
impl ::juniper::ToInputValue for #ident { impl ::juniper::ToInputValue for #ident {
fn to(&self) -> ::juniper::InputValue { fn to_input_value(&self) -> ::juniper::InputValue {
::juniper::InputValue::object(vec![ ::juniper::InputValue::object(vec![
#(#to_inputs)* #(#to_inputs)*
].into_iter().collect()) ].into_iter().collect())

View file

@ -26,14 +26,14 @@ fn test_derived_enum() {
assert_eq!(meta.description(), Some(&"enum descr".to_string())); assert_eq!(meta.description(), Some(&"enum descr".to_string()));
// Test Regular variant. // Test Regular variant.
assert_eq!(SomeEnum::Regular.to(), InputValue::String("REGULAR".into())); assert_eq!(SomeEnum::Regular.to_input_value(), InputValue::String("REGULAR".into()));
assert_eq!( assert_eq!(
FromInputValue::from_input_value(&InputValue::String("REGULAR".into())), FromInputValue::from_input_value(&InputValue::String("REGULAR".into())),
Some(SomeEnum::Regular) Some(SomeEnum::Regular)
); );
// Test FULL variant. // Test FULL variant.
assert_eq!(SomeEnum::Full.to(), InputValue::String("FULL".into())); assert_eq!(SomeEnum::Full.to_input_value(), InputValue::String("FULL".into()));
assert_eq!( assert_eq!(
FromInputValue::from_input_value(&InputValue::String("FULL".into())), FromInputValue::from_input_value(&InputValue::String("FULL".into())),
Some(SomeEnum::Full) Some(SomeEnum::Full)

View file

@ -26,6 +26,6 @@ fn test_derived_input_object() {
regular_field: "a".to_string(), regular_field: "a".to_string(),
c: 33, c: 33,
}; };
let restored: Input = FromInputValue::from_input_value(&obj.to()).unwrap(); let restored: Input = FromInputValue::from_input_value(&obj.to_input_value()).unwrap();
assert_eq!(obj, restored); assert_eq!(obj, restored);
} }