/// Parse a value as an enum value.
///
/// This can be used to implement `InputValueType::parse`.
Parse a value as an enum value.
This can be used to implement `InputValueType::parse`.
Parse a value as an enum value . This can be used to implement ` InputValueType :: parse ` .
pub fn parse_enum<T: EnumType>(value: Value) -> InputValueResult<T> {
    let value = match &value {
        Value::Enum(s) => s,
        Value::String(s) => s.as_str(),
        _ => return Err(InputValueError::ExpectedType(value)),
    };
    T::items()
        .iter()
        .find(|item| item.name == value)
        .map(|item| item.value)
        .ok_or_else(|| {
            InputValueError::Custom(format!(
                r#"Enumeration type "{}" does not contain the value "{}""#,
                T::type_name(),
                value,
            ))
        })
}
pub fn parse_enum < T : EnumType > ( value : Value ) -> InputValueResult < T > { let value = match & value { Value :: Enum ( s ) => s , Value :: String ( s ) => s . as_str ( ) , _ => return Err ( InputValueError :: ExpectedType ( value ) ) , } ; T :: items ( ) . iter ( ) . find ( | item | item . name == value ) . map ( | item | item . value ) . ok_or_else ( | | { InputValueError :: Custom ( format ! ( r#"Enumeration type "{}" does not contain the value "{}""# T type_name ( ) value ) ) } ) }
Parse a value as an enum value.
Parse a value as an enum value .
value
Value