pub fn add_def(&mut self, def: &str) -> Result<(), Error> {
        let parts: Vec<&str> = def.split(':').collect();
        match parts.len() {
            2 => {
                let name = parts[0];
                let glob = parts[1];
                if name.is_empty() || glob.is_empty() {
                    return Err(Error::InvalidDefinition);
                }
                self.add(name, glob)
            }
            3 => {
                let name = parts[0];
                let types_string = parts[2];
                if name.is_empty() || parts[1] != "include" || types_string.is_empty() {
                    return Err(Error::InvalidDefinition);
                }
                let types = types_string.split(',');
                // Check ahead of time to ensure that all types specified are
                // present and fail fast if not.
                if types.clone().any(|t| !self.types.contains_key(t)) {
                    return Err(Error::InvalidDefinition);
                }
                for type_name in types {
                    let globs = self.types.get(type_name).unwrap().globs.clone();
                    for glob in globs {
                        try!(self.add(name, &glob));
                    }
                }
                Ok(())
            }
            _ => Err(Error::InvalidDefinition)
        }
    }
/// Add a new file type definition specified in string form. There are two
/// valid formats:
/// 1. `{name}:{glob}`.  This defines a 'root' definition that associates the
///     given name with the given glob.
/// 2. `{name}:include:{comma-separated list of already defined names}.
///     This defines an 'include' definition that associates the given name
///     with the definitions of the given existing types.
/// Names may not include any characters that are not
/// Unicode letters or numbers.
Add a new file type definition specified in string form. There are two
valid formats:
1.
Add a new file type definition specified in string form . There are two valid formats : 1 .
pub fn add_def(&mut self, def: &str) -> Result<(), Error> {
        let parts: Vec<&str> = def.split(':').collect();
        match parts.len() {
            2 => {
                let name = parts[0];
                let glob = parts[1];
                if name.is_empty() || glob.is_empty() {
                    return Err(Error::InvalidDefinition);
                }
                self.add(name, glob)
            }
            3 => {
                let name = parts[0];
                let types_string = parts[2];
                if name.is_empty() || parts[1] != "include" || types_string.is_empty() {
                    return Err(Error::InvalidDefinition);
                }
                let types = types_string.split(',');
                // Check ahead of time to ensure that all types specified are
                // present and fail fast if not.
                if types.clone().any(|t| !self.types.contains_key(t)) {
                    return Err(Error::InvalidDefinition);
                }
                for type_name in types {
                    let globs = self.types.get(type_name).unwrap().globs.clone();
                    for glob in globs {
                        try!(self.add(name, &glob));
                    }
                }
                Ok(())
            }
            _ => Err(Error::InvalidDefinition)
        }
    }
pub fn add_def ( & mut self , def : & str ) -> Result < ( ) , Error > { let parts : Vec < & str > = def . split ( ':' ) . collect ( ) ; match parts . len ( ) { 2 => { let name = parts [ 0 ] ; let glob = parts [ 1 ] ; if name . is_empty ( ) || glob . is_empty ( ) { return Err ( Error :: InvalidDefinition ) ; } self . add ( name , glob ) } 3 => { let name = parts [ 0 ] ; let types_string = parts [ 2 ] ; if name . is_empty ( ) || parts [ 1 ] != " " || types_string . is_empty ( ) { return Err ( Error :: InvalidDefinition ) ; } let types = types_string . split ( ',' ) ; // Check ahead of time to ensure that all types specified are // present and fail fast if not. if types . clone ( ) . any ( | t | ! self . types . contains_key ( t ) ) { return Err ( Error :: InvalidDefinition ) ; } for type_name in types { let globs = self . types . get ( type_name ) . unwrap ( ) . globs . clone ( ) ; for glob in globs { try ! ( self add ( name glob ) ) ; } } Ok ( ( ) ) } _ => Err ( Error :: InvalidDefinition ) } }
Add a new file type definition specified in string form.
Add a new file type definition specified in string form .
&mut self
def
&str