Open
Description
Might be totally dumb question. But I couldn't make it work.
Here is my code for making Custom Scalar for u8
type.
#[juniper::graphql_scalar(description = "u8")]
impl<S> GraphQLScalar for u8 where S:ScalarValue {
fn resolve(&self) -> Value {
Value::scalar(self.to_string())
}
fn from_input_value(v : &InputValue) -> Option<u8> {
v.as_string_value().and_then(|s| s.parse::<u8>().ok())
}
fn from_str(value: ScalarToken) -> ParseScalarResult<S> {
if let ScalarToken::String(value) = value {
Ok(S::from(value.to_owned()))
} else {
Err(ParseError::UnexpectedToken(Token::Scalar(value)))
}
}
}
But I m getting error
error[E0210]: type parameter `__S` must be used as the type parameter for some local type (e.g., `MyStruct<__S>`)
--> server/src/custom_scalars/custom_u8.rs:4:1
|
4 | #[juniper::graphql_scalar(description = "u8")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `__S` must be used as the type parameter for some local type
|
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
= note: only traits defined in the current crate can be implemented for a type parameter
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0210]: type parameter `S` must be used as the type parameter for some local type (e.g., `MyStruct<S>`)
--> server/src/custom_scalars/custom_u8.rs:4:1
|
4 | #[juniper::graphql_scalar(description = "u8")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `S` must be used as the type parameter for some local type
|
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
= note: only traits defined in the current crate can be implemented for a type parameter
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
I can't figure it out what is wrong in my code. Any help or pointers are more than welcome.