fn build_chain(
            templates: &HashMap<String, Template>,
            start: &Template,
            template: &Template,
            mut parents: Vec<String>,
        ) -> Result<Vec<String>> {
            if !parents.is_empty() && start.name == template.name {
                bail!(
                    "Circular extend detected for template '{}'. Inheritance chain: `{:?}`",
                    start.name,
                    parents,
                );
            }

            match template.parent {
                Some(ref p) => match templates.get(p) {
                    Some(parent) => {
                        parents.push(parent.name.clone());
                        build_chain(templates, start, parent, parents)
                    }
                    None => bail!(
                        "Template '{}' is inheriting from '{}', which doesn't exist or isn't loaded.",
                        template.name, p,
                    ),
                },
                None => Ok(parents),
            }
        }
// Recursive fn that finds all the parents and put them in an ordered Vec from closest to first parent
// parent template
Recursive fn that finds all the parents and put them in an ordered Vec from closest to first parent
parent template
Recursive fn that finds all the parents and put them in an ordered Vec from closest to first parent parent template
fn build_chain(
            templates: &HashMap<String, Template>,
            start: &Template,
            template: &Template,
            mut parents: Vec<String>,
        ) -> Result<Vec<String>> {
            if !parents.is_empty() && start.name == template.name {
                bail!(
                    "Circular extend detected for template '{}'. Inheritance chain: `{:?}`",
                    start.name,
                    parents,
                );
            }
            match template.parent {
                Some(ref p) => match templates.get(p) {
                    Some(parent) => {
                        parents.push(parent.name.clone());
                        build_chain(templates, start, parent, parents)
                    }
                    None => bail!(
                        "Template '{}' is inheriting from '{}', which doesn't exist or isn't loaded.",
                        template.name, p,
                    ),
                },
                None => Ok(parents),
            }
        }
fn build_chain ( templates : & HashMap < String , Template > , start : & Template , template : & Template , mut parents : Vec < String > , ) -> Result < Vec < String > > { if ! parents . is_empty ( ) && start . name == template . name { bail ! ( " " start name parents ) ; } match template . parent { Some ( ref p ) => match templates . get ( p ) { Some ( parent ) => { parents . push ( parent . name . clone ( ) ) ; build_chain ( templates , start , parent , parents ) } None => bail ! ( " " template name p ) , } , None => Ok ( parents ) , } }
Recursive fn that finds all the parents and put them in an ordered Vec from closest to first parent
parent template
Recursive fn that finds all the parents and put them in an ordered Vec from closest to first parent parent template
templates
&HashMap<String, Template>
start
&Template
template
&Template
parents
Vec<String>
templates
&HashMap<String, Template>
start
&Template
template
&Template
parents
Vec<String>