// just print the name of the type
just print the name of the type
just print the name of the type
fn print_name<K, T>(key: &K, t: &T) -> String
where
    K: BuilderKey,
    T: Index<K, Output = TypeVariant<K>>,
{
    match t.index(key.clone()) {
        TypeVariant::Primitive(p) => p.to_string(),
        TypeVariant::Option(opt) => format!("Option<{}>", print_name(opt, t)),
        TypeVariant::UnitStruct(name) => name.to_string(),
        TypeVariant::Enum(name, _) => name.to_string(),
        TypeVariant::NewType(name, _) => name.to_string(),
        TypeVariant::Seq(typ, len) => format!(
            "[ {} ; {} ]",
            print_name(typ, t),
            len.map_or("?".to_string(), |l| l.to_string())
        ),
        TypeVariant::Tuple(types) => {
            let types = types
                .iter()
                .map(|subtype| print_name(subtype, t))
                .collect::<Vec<_>>()
                .join(", ");
            format!("({})", types)
        }
        TypeVariant::TupleStruct(name, _) => name.to_string(),
        TypeVariant::Map(key, val, len) => format!(
            "{{ {}: {} ; {} }}",
            print_name(key, t),
            print_name(val, t),
            len.map_or("?".to_string(), |l| l.to_string())
        ),
        TypeVariant::Struct(name, _) => name.to_string(),
    }
}
fn print_name < K , T > ( key : & K , t : & T ) -> String where K : BuilderKey , T : Index < K , Output = TypeVariant < K > > , { match t . index ( key . clone ( ) ) { TypeVariant :: Primitive ( p ) => p . to_string ( ) , TypeVariant :: Option ( opt ) => format ! ( " " print_name ( opt t ) ) , TypeVariant :: UnitStruct ( name ) => name . to_string ( ) , TypeVariant :: Enum ( name , _ ) => name . to_string ( ) , TypeVariant :: NewType ( name , _ ) => name . to_string ( ) , TypeVariant :: Seq ( typ , len ) => format ! ( " " print_name ( typ t ) len map_or ( " " to_string ( ) l l to_string ( ) ) ) , TypeVariant :: Tuple ( types ) => { let types = types . iter ( ) . map ( | subtype | print_name ( subtype , t ) ) . collect :: < Vec < _ > > ( ) . join ( " " ) ; format ! ( " " types ) } TypeVariant :: TupleStruct ( name , _ ) => name . to_string ( ) , TypeVariant :: Map ( key , val , len ) => format ! ( " " print_name ( key t ) print_name ( val t ) len map_or ( " " to_string ( ) l l to_string ( ) ) ) , TypeVariant :: Struct ( name , _ ) => name . to_string ( ) , } }
just print the name of the type
just print the name of the type
key
&K
t
&T