fn to_json_generic_enum<I, C>(
    variant_snake_case: String,
    rest_of_stream: &mut I,
    type_name: &str,
    rti: &ReflectedTypeInfo,
    ctx: &mut C,
) -> Result<String, String>
where
    C: TestDeserializeContext,
    I: Iterator<Item = TokenTree>,
{
    // Convert the variant from snake_case to CamelCase
    let variant_camel_case = variant_snake_case
        .split('_')
        .map(|s| {
            let mut chars = s.chars();
            let result = chars
                .next()
                .map(|c| c.to_uppercase().chain(chars).collect::<String>())
                .unwrap_or_else(String::new);
            result
        })
        .collect::<Vec<_>>()
        .concat();
    let (f_names, f_types) = rti
        .enum_dict
        .get(type_name)
        .unwrap()
        .get(&variant_camel_case[..])
        .map(|v| v.clone())
        .ok_or_else(|| {
            format!(
                "{}::{} is not a supported enum.",
                type_name, variant_camel_case
            )
        })?;
    // If we reach end of stream before getting a value for each field,
    // we assume that the fields we don't have values for are optional.
    if f_types.is_empty() {
        // The JSON for a unit enum is just `"variant"`.
        Ok(format!("\"{}\"", variant_camel_case))
    } else {
        let fields = to_json_fields(
            &variant_camel_case,
            rest_of_stream,
            f_names,
            f_types,
            rti,
            ctx,
        )?;
        Ok(format!("{{\"{}\":{}}}", variant_camel_case, fields))
    }
}
/// Converts the spec of an enum into deserializable JSON
Converts the spec of an enum into deserializable JSON
Converts the spec of an enum into deserializable JSON
fn to_json_generic_enum<I, C>(
    variant_snake_case: String,
    rest_of_stream: &mut I,
    type_name: &str,
    rti: &ReflectedTypeInfo,
    ctx: &mut C,
) -> Result<String, String>
where
    C: TestDeserializeContext,
    I: Iterator<Item = TokenTree>,
{
    // Convert the variant from snake_case to CamelCase
    let variant_camel_case = variant_snake_case
        .split('_')
        .map(|s| {
            let mut chars = s.chars();
            let result = chars
                .next()
                .map(|c| c.to_uppercase().chain(chars).collect::<String>())
                .unwrap_or_else(String::new);
            result
        })
        .collect::<Vec<_>>()
        .concat();
    let (f_names, f_types) = rti
        .enum_dict
        .get(type_name)
        .unwrap()
        .get(&variant_camel_case[..])
        .map(|v| v.clone())
        .ok_or_else(|| {
            format!(
                "{}::{} is not a supported enum.",
                type_name, variant_camel_case
            )
        })?;
    // If we reach end of stream before getting a value for each field,
    // we assume that the fields we don't have values for are optional.
    if f_types.is_empty() {
        // The JSON for a unit enum is just `"variant"`.
        Ok(format!("\"{}\"", variant_camel_case))
    } else {
        let fields = to_json_fields(
            &variant_camel_case,
            rest_of_stream,
            f_names,
            f_types,
            rti,
            ctx,
        )?;
        Ok(format!("{{\"{}\":{}}}", variant_camel_case, fields))
    }
}
fn to_json_generic_enum < I , C > ( variant_snake_case : String , rest_of_stream : & mut I , type_name : & str , rti : & ReflectedTypeInfo , ctx : & mut C , ) -> Result < String , String > where C : TestDeserializeContext , I : Iterator < Item = TokenTree > , { // Convert the variant from snake_case to CamelCase let variant_camel_case = variant_snake_case . split ( '_' ) . map ( | s | { let mut chars = s . chars ( ) ; let result = chars . next ( ) . map ( | c | c . to_uppercase ( ) . chain ( chars ) . collect :: < String > ( ) ) . unwrap_or_else ( String :: new ) ; result } ) . collect :: < Vec < _ > > ( ) . concat ( ) ; let ( f_names , f_types ) = rti . enum_dict . get ( type_name ) . unwrap ( ) . get ( & variant_camel_case [ .. ] ) . map ( | v | v . clone ( ) ) . ok_or_else ( | | { format ! ( " " type_name variant_camel_case ) } ) ? ; // If we reach end of stream before getting a value for each field, // we assume that the fields we don't have values for are optional. if f_types . is_empty ( ) { // The JSON for a unit enum is just `"variant"`. Ok ( format ! ( " \" \" " variant_camel_case ) ) } else { let fields = to_json_fields ( & variant_camel_case , rest_of_stream , f_names , f_types , rti , ctx , ) ? ; Ok ( format ! ( " \" \" " variant_camel_case fields ) ) } }
Converts the spec of an enum into deserializable JSON
Converts the spec of an enum into deserializable JSON
variant_snake_case
String
rest_of_stream
&mut I
type_name
&str
rti
&ReflectedTypeInfo
ctx
&mut C
variant_snake_case
String
rest_of_stream
&mut I
type_name
&str
rti
&ReflectedTypeInfo
ctx
&mut C