fn try_from(ast: &AST) -> TypeResult<Name> {
        match &ast.node {
            Node::Id { lit } => Ok(Name::from(&DirectName::from(lit.as_str()))),
            Node::QuestionOp { expr } => Ok(Name::try_from(expr)?.as_nullable()),
            Node::Type { .. } => Ok(Name::from(&DirectName::try_from(ast)?)),
            Node::TypeTup { types } => {
                let names = types.iter().map(NameUnion::try_from).collect::<Result<_, _>>()?;
                Ok(Name::from(&NameVariant::Tuple(names)))
            }
            Node::TypeFun { args, ret_ty } => Ok(Name::from(&NameVariant::Fun(
                args.iter().map(NameUnion::try_from).collect::<Result<_, _>>()?,
                Box::from(NameUnion::try_from(ret_ty.deref())?)
            ))),
            Node::TypeUnion { .. } =>
                Err(vec![TypeErr::new(&ast.pos, "Expected single name but was union")]),
            Node::Generic { id, .. } => Name::try_from(id),
            _ => {
                let msg = format!("Expected name, was {}", ast.node);
                Err(vec![TypeErr::new(&ast.pos, &msg)])
            }
        }
    }
/// Try to construct Name from AST.
///
/// In the case of Generics, isa field is ignored and we only look at the
/// name of the generic itself.
Try to construct Name from AST.
In the case of Generics, isa field is ignored and we only look at the
name of the generic itself.
Try to construct Name from AST . In the case of Generics isa field is ignored and we only look at the name of the generic itself .
fn try_from(ast: &AST) -> TypeResult<Name> {
        match &ast.node {
            Node::Id { lit } => Ok(Name::from(&DirectName::from(lit.as_str()))),
            Node::QuestionOp { expr } => Ok(Name::try_from(expr)?.as_nullable()),
            Node::Type { .. } => Ok(Name::from(&DirectName::try_from(ast)?)),
            Node::TypeTup { types } => {
                let names = types.iter().map(NameUnion::try_from).collect::<Result<_, _>>()?;
                Ok(Name::from(&NameVariant::Tuple(names)))
            }
            Node::TypeFun { args, ret_ty } => Ok(Name::from(&NameVariant::Fun(
                args.iter().map(NameUnion::try_from).collect::<Result<_, _>>()?,
                Box::from(NameUnion::try_from(ret_ty.deref())?)
            ))),
            Node::TypeUnion { .. } =>
                Err(vec![TypeErr::new(&ast.pos, "Expected single name but was union")]),
            Node::Generic { id, .. } => Name::try_from(id),
            _ => {
                let msg = format!("Expected name, was {}", ast.node);
                Err(vec![TypeErr::new(&ast.pos, &msg)])
            }
        }
    }
fn try_from ( ast : & AST ) -> TypeResult < Name > { match & ast . node { Node :: Id { lit } => Ok ( Name :: from ( & DirectName :: from ( lit . as_str ( ) ) ) ) , Node :: QuestionOp { expr } => Ok ( Name :: try_from ( expr ) ? . as_nullable ( ) ) , Node :: Type { .. } => Ok ( Name :: from ( & DirectName :: try_from ( ast ) ? ) ) , Node :: TypeTup { types } => { let names = types . iter ( ) . map ( NameUnion :: try_from ) . collect :: < Result < _ , _ > > ( ) ? ; Ok ( Name :: from ( & NameVariant :: Tuple ( names ) ) ) } Node :: TypeFun { args , ret_ty } => Ok ( Name :: from ( & NameVariant :: Fun ( args . iter ( ) . map ( NameUnion :: try_from ) . collect :: < Result < _ , _ > > ( ) ? , Box :: from ( NameUnion :: try_from ( ret_ty . deref ( ) ) ? ) ) ) ) , Node :: TypeUnion { .. } => Err ( vec ! [ TypeErr new ( ast pos " " ) ] ) , Node :: Generic { id , .. } => Name :: try_from ( id ) , _ => { let msg = format ! ( " " ast node ) ; Err ( vec ! [ TypeErr new ( ast pos msg ) ] ) } } }
Try to construct Name from AST.
Try to construct Name from AST .
ast
&AST