Rename FromInputValue::from() to from_input_value()

This commit is contained in:
theduke 2017-08-29 04:35:14 +02:00 committed by theduke
parent 0915c05c6c
commit 164aa29fdc
15 changed files with 27 additions and 27 deletions

View file

@ -154,7 +154,7 @@ pub type Document<'a> = Vec<Definition<'a>>;
/// enums or scalars.
pub trait FromInputValue: Sized {
/// Performs the conversion.
fn from(v: &InputValue) -> Option<Self>;
fn from_input_value(v: &InputValue) -> Option<Self>;
}
/// Losslessly clones a Rust data type into an InputValue.
@ -302,7 +302,7 @@ impl InputValue {
where
T: FromInputValue,
{
<T as FromInputValue>::from(self)
<T as FromInputValue>::from_input_value(self)
}
/// Does the value represent null?

View file

@ -24,7 +24,7 @@ mod test {
let raw = "123e4567-e89b-12d3-a456-426655440000";
let input = ::InputValue::String(raw.to_string());
let parsed: Uuid = ::FromInputValue::from(&input).unwrap();
let parsed: Uuid = ::FromInputValue::from_input_value(&input).unwrap();
let id = Uuid::parse_str(raw).unwrap();
assert_eq!(parsed, id);

View file

@ -94,7 +94,7 @@ macro_rules! graphql_enum {
}
impl $crate::FromInputValue for $name {
fn from(v: &$crate::InputValue) -> Option<$name> {
fn from_input_value(v: &$crate::InputValue) -> Option<$name> {
match v.as_enum_value().or_else(|| v.as_string_value()) {
$(
Some(graphql_enum!(@as_pattern, $ename))

View file

@ -69,8 +69,8 @@ macro_rules! graphql_input_object {
match v {
$( Some(&&$crate::InputValue::Null) | None if true => $default, )*
Some(v) => $crate::FromInputValue::from(v).unwrap(),
_ => $crate::FromInputValue::from(&$crate::InputValue::null()).unwrap()
Some(v) => $crate::FromInputValue::from_input_value(v).unwrap(),
_ => $crate::FromInputValue::from_input_value(&$crate::InputValue::null()).unwrap()
}
} ),*
})
@ -221,7 +221,7 @@ macro_rules! graphql_input_object {
graphql_input_object!(@generate_struct_fields, $meta, $pubmod, $name, $fields);
impl $crate::FromInputValue for $name {
fn from(value: &$crate::InputValue) -> Option<$name> {
fn from_input_value(value: &$crate::InputValue) -> Option<$name> {
if let Some(obj) = value.to_object_value() {
graphql_input_object!(@generate_from_input_value, $name, obj, $fields)
}

View file

@ -94,7 +94,7 @@ macro_rules! graphql_scalar {
}
impl $crate::FromInputValue for $name {
fn from($fiv_arg: &$crate::InputValue) -> $fiv_result {
fn from_input_value($fiv_arg: &$crate::InputValue) -> $fiv_result {
$fiv_body
}
}

View file

@ -194,7 +194,7 @@ fn default_name_input_value() {
.collect(),
);
let dv: Option<DefaultName> = FromInputValue::from(&iv);
let dv: Option<DefaultName> = FromInputValue::from_input_value(&iv);
assert!(dv.is_some());

View file

@ -345,7 +345,7 @@ impl<'a> ScalarMeta<'a> {
ScalarMeta {
name: name,
description: None,
try_parse_fn: Box::new(|v: &InputValue| <T as FromInputValue>::from(v).is_some()),
try_parse_fn: Box::new(|v: &InputValue| <T as FromInputValue>::from_input_value(v).is_some()),
}
}
@ -431,7 +431,7 @@ impl<'a> EnumMeta<'a> {
name: name,
description: None,
values: values.to_vec(),
try_parse_fn: Box::new(|v: &InputValue| <T as FromInputValue>::from(v).is_some()),
try_parse_fn: Box::new(|v: &InputValue| <T as FromInputValue>::from_input_value(v).is_some()),
}
}
@ -510,7 +510,7 @@ impl<'a> InputObjectMeta<'a> {
name: name,
description: None,
input_fields: input_fields.to_vec(),
try_parse_fn: Box::new(|v: &InputValue| <T as FromInputValue>::from(v).is_some()),
try_parse_fn: Box::new(|v: &InputValue| <T as FromInputValue>::from_input_value(v).is_some()),
}
}

View file

@ -37,7 +37,7 @@ impl<T> FromInputValue for Option<T>
where
T: FromInputValue,
{
fn from(v: &InputValue) -> Option<Option<T>> {
fn from_input_value(v: &InputValue) -> Option<Option<T>> {
match v {
&InputValue::Null => Some(None),
v => match v.convert() {
@ -93,7 +93,7 @@ impl<T> FromInputValue for Vec<T>
where
T: FromInputValue,
{
fn from(v: &InputValue) -> Option<Vec<T>> {
fn from_input_value(v: &InputValue) -> Option<Vec<T>> {
match *v {
InputValue::List(ref ls) => {
let v: Vec<_> = ls.iter().filter_map(|i| i.item.convert()).collect();

View file

@ -54,8 +54,8 @@ impl<T> FromInputValue for Box<T>
where
T: FromInputValue,
{
fn from(v: &InputValue) -> Option<Box<T>> {
match <T as FromInputValue>::from(v) {
fn from_input_value(v: &InputValue) -> Option<Box<T>> {
match <T as FromInputValue>::from_input_value(v) {
Some(v) => Some(Box::new(v)),
None => None,
}

View file

@ -141,7 +141,7 @@ impl GraphQLType for () {
}
impl FromInputValue for () {
fn from(_: &InputValue) -> Option<()> {
fn from_input_value(_: &InputValue) -> Option<()> {
None
}
}

View file

@ -131,7 +131,7 @@ impl GraphQLType for DogCommand {
}
impl FromInputValue for DogCommand {
fn from(v: &InputValue) -> Option<DogCommand> {
fn from_input_value(v: &InputValue) -> Option<DogCommand> {
match v.as_enum_value() {
Some("SIT") => Some(DogCommand::Sit),
Some("HEEL") => Some(DogCommand::Heel),
@ -204,7 +204,7 @@ impl GraphQLType for FurColor {
}
impl FromInputValue for FurColor {
fn from(v: &InputValue) -> Option<FurColor> {
fn from_input_value(v: &InputValue) -> Option<FurColor> {
match v.as_enum_value() {
Some("BROWN") => Some(FurColor::Brown),
Some("BLACK") => Some(FurColor::Black),
@ -382,7 +382,7 @@ impl GraphQLType for ComplexInput {
}
impl FromInputValue for ComplexInput {
fn from(v: &InputValue) -> Option<ComplexInput> {
fn from_input_value(v: &InputValue) -> Option<ComplexInput> {
let obj = match v.to_object_value() {
Some(o) => o,
None => return None,

View file

@ -172,7 +172,7 @@ pub fn impl_enum(ast: &syn::DeriveInput) -> Tokens {
}
impl ::juniper::FromInputValue for #ident {
fn from(v: &::juniper::InputValue) -> Option<#ident> {
fn from_input_value(v: &::juniper::InputValue) -> Option<#ident> {
match v.as_enum_value().or_else(|| v.as_string_value()) {
#(#from_inputs)*
_ => None,

View file

@ -169,8 +169,8 @@ pub fn impl_input_object(ast: &syn::DeriveInput) -> Tokens {
// TODO: investigate the unwraps here, they seem dangerous!
match obj.get(#name) {
#from_input_default
Some(v) => ::juniper::FromInputValue::from(v).unwrap(),
_ => ::juniper::FromInputValue::from(&::juniper::InputValue::null()).unwrap()
Some(v) => ::juniper::FromInputValue::from_input_value(v).unwrap(),
_ => ::juniper::FromInputValue::from_input_value(&::juniper::InputValue::null()).unwrap()
}
},
};
@ -203,7 +203,7 @@ pub fn impl_input_object(ast: &syn::DeriveInput) -> Tokens {
}
impl ::juniper::FromInputValue for #ident {
fn from(value: &::juniper::InputValue) -> Option<#ident> {
fn from_input_value(value: &::juniper::InputValue) -> Option<#ident> {
if let Some(obj) = value.to_object_value() {
let item = #ident {
#(#from_inputs)*

View file

@ -28,14 +28,14 @@ fn test_derived_enum() {
// Test Regular variant.
assert_eq!(SomeEnum::Regular.to(), InputValue::String("REGULAR".into()));
assert_eq!(
FromInputValue::from(&InputValue::String("REGULAR".into())),
FromInputValue::from_input_value(&InputValue::String("REGULAR".into())),
Some(SomeEnum::Regular)
);
// Test FULL variant.
assert_eq!(SomeEnum::Full.to(), InputValue::String("FULL".into()));
assert_eq!(
FromInputValue::from(&InputValue::String("FULL".into())),
FromInputValue::from_input_value(&InputValue::String("FULL".into())),
Some(SomeEnum::Full)
);
}

View file

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