fn add_file<P: AsRef<Path>>(&mut self, name: Option<&str>, path: P) -> Result<()> {
        let path = path.as_ref();
        let tpl_name = name.unwrap_or_else(|| path.to_str().unwrap());

        let mut f =
            File::open(path).chain_err(|| format!("Couldn't open template '{:?}'", path))?;

        let mut input = String::new();
        f.read_to_string(&mut input)
            .chain_err(|| format!("Failed to read template '{:?}'", path))?;

        let tpl = Template::new(tpl_name, Some(path.to_str().unwrap().to_string()), &input)
            .chain_err(|| format!("Failed to parse {:?}", path))?;

        self.templates.insert(tpl_name.to_string(), tpl);
        Ok(())
    }
// Add a template from a path: reads the file and parses it.
// This will return an error if the template is invalid and doesn't check the validity of
// inheritance chains.
Add a template from a path: reads the file and parses it.
This will return an error if the template is invalid and doesn't check the validity of
inheritance chains.
Add a template from a path : reads the file and parses it . This will return an error if the template is invalid and doesn ' t check the validity of inheritance chains .
fn add_file<P: AsRef<Path>>(&mut self, name: Option<&str>, path: P) -> Result<()> {
        let path = path.as_ref();
        let tpl_name = name.unwrap_or_else(|| path.to_str().unwrap());
        let mut f =
            File::open(path).chain_err(|| format!("Couldn't open template '{:?}'", path))?;
        let mut input = String::new();
        f.read_to_string(&mut input)
            .chain_err(|| format!("Failed to read template '{:?}'", path))?;
        let tpl = Template::new(tpl_name, Some(path.to_str().unwrap().to_string()), &input)
            .chain_err(|| format!("Failed to parse {:?}", path))?;
        self.templates.insert(tpl_name.to_string(), tpl);
        Ok(())
    }
fn add_file < P : AsRef < Path > > ( & mut self , name : Option < & str > , path : P ) -> Result < ( ) > { let path = path . as_ref ( ) ; let tpl_name = name . unwrap_or_else ( | | path . to_str ( ) . unwrap ( ) ) ; let mut f = File :: open ( path ) . chain_err ( | | format ! ( " " path ) ) ? ; let mut input = String :: new ( ) ; f . read_to_string ( & mut input ) . chain_err ( | | format ! ( " " path ) ) ? ; let tpl = Template :: new ( tpl_name , Some ( path . to_str ( ) . unwrap ( ) . to_string ( ) ) , & input ) . chain_err ( | | format ! ( " " path ) ) ? ; self . templates . insert ( tpl_name . to_string ( ) , tpl ) ; Ok ( ( ) ) }
Add a template from a path: reads the file and parses it.
Add a template from a path : reads the file and parses it .
&mut self
name
Option<&str>
path
P
&mut self
name
Option<&str>
path
P