pub fn add(&mut self, category: Category) -> Result<()> {
        if self.categories.contains_key(&category.name.to_lowercase()) {
            return Ok(()); // No-op. Maybe emit a warning?
        }

        for name in category.all_names() {
            if self.by_name_or_alias.contains_key(&name.to_lowercase()) {
                bail!(
                    "Duplicate category key: '{}' is used by '{}' and '{}'",
                    name,
                    category.name,
                    self.find(name).unwrap().name
                );
            }
        }

        let cat_rc = Rc::new(category);

        self.categories
            .insert(String::from(&cat_rc.name).to_lowercase(), cat_rc.clone());

        for name in cat_rc.all_names() {
            self.by_name_or_alias
                .insert(name.to_string().to_lowercase(), cat_rc.clone());
        }

        Ok(())
    }
/// Add the given category to the lookup.
/// Re-adding a category will be silently ignored. Adding a category with a name or alias that
/// is already in use will create an Err
Add the given category to the lookup.
Re-adding a category will be silently ignored. Adding a category with a name or alias that
is already in use will create an Err
Add the given category to the lookup . Re - adding a category will be silently ignored . Adding a category with a name or alias that is already in use will create an Err
pub fn add(&mut self, category: Category) -> Result<()> {
        if self.categories.contains_key(&category.name.to_lowercase()) {
            return Ok(()); // No-op. Maybe emit a warning?
        }
        for name in category.all_names() {
            if self.by_name_or_alias.contains_key(&name.to_lowercase()) {
                bail!(
                    "Duplicate category key: '{}' is used by '{}' and '{}'",
                    name,
                    category.name,
                    self.find(name).unwrap().name
                );
            }
        }
        let cat_rc = Rc::new(category);
        self.categories
            .insert(String::from(&cat_rc.name).to_lowercase(), cat_rc.clone());
        for name in cat_rc.all_names() {
            self.by_name_or_alias
                .insert(name.to_string().to_lowercase(), cat_rc.clone());
        }
        Ok(())
    }
pub fn add ( & mut self , category : Category ) -> Result < ( ) > { if self . categories . contains_key ( & category . name . to_lowercase ( ) ) { return Ok ( ( ) ) ; // No-op. Maybe emit a warning? } for name in category . all_names ( ) { if self . by_name_or_alias . contains_key ( & name . to_lowercase ( ) ) { bail ! ( " " name category name self find ( name ) unwrap ( ) name ) ; } } let cat_rc = Rc :: new ( category ) ; self . categories . insert ( String :: from ( & cat_rc . name ) . to_lowercase ( ) , cat_rc . clone ( ) ) ; for name in cat_rc . all_names ( ) { self . by_name_or_alias . insert ( name . to_string ( ) . to_lowercase ( ) , cat_rc . clone ( ) ) ; } Ok ( ( ) ) }
Add the given category to the lookup.
Add the given category to the lookup .
&mut self
category
Category