Hashmaps are a powerful data structure that allow you to store key-value pairs. In Rust, the HashMap type is provided that uses the a hashing algorithm called SipHash to store keys and values in a way that allows for fast and secure lookups. Think of them as a dictionary in Python or an object in JavaScript.
In this challenge, we want to build a sanctuary registry that allows us to manage animals in different sections of the sanctuary. We'll use a HashMap to store the sections as keys and a Vec to store the animals in each section. Each key is a section name String and each value is a list of animals in that section Vec<String>.
You are given a type of Collection which is a HashMap<String, Vec<String>>. The key is the section name and the value is a list of animals in that section.
Your task is to implement the following functions:
add_animal_to_section: This function should add an animal to a section in the registry. If the section does not exist, it should be created. If the animal is already in the section, it should not be added again.
get_animals_in_section: This function should return a list of animals sorted alphabetically in a given section. If the section does not exist, it should return an empty list.
get_all_animals_sorted: This function should return a copy of the entire registry with all animals sorted alphabetically in each section.
let mut registry = Collection::new();
 
add_animal_to_section("Eagle", "Birds", &mut registry);
assert_eq!(get_animals_in_section("Birds", ®istry), vec!["Eagle"]);insert method on a HashMap to add a new section or update an existing section.entry method on a HashMap to get a mutable reference to a section.iter method on a HashMap to iterate over the key-value pairs.sort method on a Vec to sort the animals alphabetically.use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // This function should add an animal to a section in the registry.    // If the section does not exist, it should be created.    // If the animal is already in the section, it should not be added again.    if registry.contains_key(section) {        let _sec = registry.get_mut(section).unwrap();        for t in _sec.iter() {            if animal == t {                return;            }        }        registry            .get_mut(section)            .unwrap()            .push(String::from(animal));    } else {        registry.insert(String::from(section), vec![String::from(animal)]);    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // This function should return a list of animals sorted alphabetically in a given section.    // If the section does not exist, it should return an empty list.    if registry.contains_key(section) {        sort_string_vec( registry.get(section).unwrap().clone())    } else {        Vec::new()    }}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // This function should return a copy of the entire registry    // with all animals sorted alphabetically in each section.    let mut ret = Vec::new();    for x in registry {        ret.append(&mut x.1.clone());    }    sort_string_vec(ret)}pub fn sort_string_vec(mut ret: Vec<String>) -> Vec<String> {    ret.sort_by(|a, b| a.partial_cmp(b).unwrap());    ret}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    if let Some(v) = registry.get_mut(section) {        if !v.contains(&String::from(animal)) {            v.push(String::from(animal));        }    } else {        registry.insert(String::from(section), vec![String::from(animal)]);    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    if let Some(v) = registry.get(section) {        let mut s = v.clone();        s.sort();        s    } else {        vec![]    }}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut res: Vec<String> = vec![];    for key in registry.keys() {        if let Some(v) = registry.get(key) {            let s = v.clone();            res.extend(s);        }    }    res.sort();    res}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    if let Some(v) = registry.get_mut(section) {        if !v.contains(&String::from(animal)) {            v.push(String::from(animal));        }    } else {        registry.insert(String::from(section), vec![String::from(animal)]);    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    if let Some(v) = registry.get(section) {        let mut s = v.clone();        s.sort();        s    } else {        vec![]    }}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut res: Vec<String> = vec![];    for key in registry.keys() {        if let Some(v) = registry.get(key) {            let s = v.clone();            res.extend(s);        }    }    res.sort();    res}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    let animals = registry.entry(section.to_string()).or_default();    if !animals.contains(&animal.to_string()) {        animals.push(animal.to_string());    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let mut animals_in_section: Vec<String> = registry        .get(section)        .cloned()        .unwrap_or_default();            animals_in_section.sort();    animals_in_section}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut all_animals: Vec<String> = registry        .values()        .flatten()        .cloned()        .collect();    all_animals.sort();    all_animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    if let Some(animals) = registry.get_mut(section) {        if !animals.contains(&animal.to_string()) {            animals.push(animal.to_string());        }    } else {        let mut animals = Vec::new();        animals.push(animal.to_string());        registry.insert(section.to_string(), animals);    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // TODO: implement this function    if let Some(animals) = registry.get(section) {        let mut sorted_animals = animals.clone();        sorted_animals.sort();        return sorted_animals;    }     let animals: Vec<String> = Vec::new();    animals}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut animals: Vec<String> = Vec::new();    for all in registry.values() {        animals.extend(all.clone());    }    animals.sort();    animals}// Difficulty suddenly went off the roof with this one. Couldn't solve it without having to cheat by asking ChatGPT to generate the code and explain every bit of it like I'm the dumbest person on Earth. Damn! Although I understand (almost) everything about it now, I'm still considering this a failure.use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    let animals = registry.entry(section.to_string()).or_default();    if !animals.contains(&animal.to_string()) {        animals.push(animal.to_string())    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut result = registry.get(section).cloned().unwrap_or_default();    result.sort();    result}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut result: Vec<_> = registry.values().flatten().cloned().collect();    result.sort();    result}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    let animals = registry.entry(String::from(section)).or_insert_with(Vec::new);    //let animals = registry.entry(section.to_string()).or_insert(Vec::new());    //if !animals.iter().any(|a| a == animal) {    if !animals.contains(&animal.to_string()) {        animals.push(String::from(animal));    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // TODO: implement this function    /*let mut animals = registry.get(section).map(|animals| animals.clone()).unwrap_or_default();    animals.sort();*/    let mut result = Vec::new();    if let Some(animals) = registry.get(section) {        for animal in animals {            result.push(animal.to_string());        }        result.sort();    }    result}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut all_animals: Vec<String> = registry        .values()        .flat_map(|animals| animals.iter())        .cloned()        .collect();    all_animals.sort_unstable();    all_animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    //let animals = registry.entry(String::from(section)).or_insert_with(Vec::new);    let animals = registry.entry(section.to_string()).or_insert(Vec::new());    //if !animals.iter().any(|a| a == animal) {    if !animals.contains(&animal.to_string()) {        animals.push(String::from(animal));    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut animals = registry.get(section).map(|animals| animals.clone()).unwrap_or_default();    animals.sort();    animals}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut all_animals: Vec<String> = registry        .values()        .flat_map(|animals| animals.iter())        .cloned()        .collect();    all_animals.sort_unstable();    all_animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    let animals = registry.entry(String::from(section)).or_insert_with(Vec::new);    //if !animals.iter().any(|a| a == animal) {    if !animals.contains(&animal.to_string()) {        animals.push(String::from(animal));    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut animals = registry.get(section).map(|animals| animals.clone()).unwrap_or_default();    animals.sort();    animals}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut all_animals: Vec<String> = registry        .values()        .flat_map(|animals| animals.iter())        .cloned()        .collect();    all_animals.sort_unstable();    all_animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    match registry.get_mut(section) {        Some(entry) => {            if !entry.contains(&animal.to_string()) {                entry.push(animal.to_string())            }        }        None => {            registry.insert(section.to_string(), vec![animal.to_string()]);        }    };}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let mut animals = registry.get(section).unwrap_or(&vec![]).clone();    animals.sort();    return animals;}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut animals = registry.values().flatten().cloned().collect::<Vec<_>>();    animals.sort();    return animals;}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    let animals = registry.entry(section.to_string()).or_default();    if !animals.contains(&animal.to_string()) {        animals.push(animal.to_string());    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let mut animals_in_section: Vec<String> = registry        .get(section)        .cloned()        .unwrap_or_default();            animals_in_section.sort();    animals_in_section}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut all_animals: Vec<String> = registry        .values()        .flatten()        .cloned()        .collect();    all_animals.sort();    all_animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    let animals = registry.entry(String::from(section)).or_insert_with(Vec::new);    //if !animals.iter().any(|a| a == animal) {    if !animals.contains(&animal.to_string()) {        animals.push(String::from(animal));    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut animals = registry.get(section).map(|animals| animals.clone()).unwrap_or_default();    animals.sort();    animals}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut all_animals: Vec<String> = registry        .values()        .flat_map(|animals| animals.iter())        .cloned()        .collect();    all_animals.sort_unstable();    all_animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    let animals = registry.entry(String::from(section)).or_insert_with(Vec::new);    if !animals.iter().any(|a| a == animal) {        animals.push(String::from(animal));    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut animals = registry.get(section).map(|animals| animals.clone()).unwrap_or_default();    animals.sort();    animals}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut all_animals: Vec<String> = registry        .values()        .flat_map(|animals| animals.iter())        .cloned()        .collect();    all_animals.sort_unstable();    all_animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    if let Some(vec) = registry.get_mut(section){        if !vec.contains(&animal.to_string()){            vec.push(animal.to_string());        }    }else{        registry.insert(section.to_string(),vec![animal.to_string()]);    }}pub fn get_animals_in_section(section: &str, registry: & Collection) -> Vec<String> {    if let Some(vec) = registry.get(section){        let mut new_vec = vec.clone();        new_vec.sort();        return new_vec;    }else {        return vec![];    }}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut sorted_list =   vec![];    for (_key,value) in registry.iter(){        for i in value {            sorted_list.push(i.to_string())        }    }    sorted_list.sort();    sorted_list}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    registry.entry(section.to_string()).and_modify(|a| {        if ! a.contains(&animal.to_string()) {a.push(animal.to_string())}    }).or_insert(vec![animal.to_string()]);}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut animals = registry.get(section).cloned().unwrap_or(vec![]);    animals.sort();    animals}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut sorted_animals: Vec<String> = registry.iter().map(|(_, animals)| animals.clone()).flatten().collect();    sorted_animals.sort();    sorted_animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    let animals = registry.entry(section.to_string()).or_insert(Vec::new());    if !animals.contains(&animal.to_string()){        animals.push(animal.to_string());    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut animals = match registry.get(section){        Some(res) => res.clone(),        None => Vec::new(),    };    animals.sort();    animals}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut result = Vec::new();    for animals in registry.values(){        for a in animals{            result.push(a.to_string());        }    }    result.sort();    result}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    registry.entry(section.to_string())        .and_modify(|s| {            if s.iter().position(|e| e == animal).is_none() {                s.push(animal.to_string())            }        })        .or_insert(vec![animal.to_string()]);}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut animals = registry.get(section).cloned().unwrap_or(vec![]);    animals.sort();    animals}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut all_animals: Vec<String> = registry.iter().map(|(_, animals)| animals.clone()).flatten().collect();    all_animals.sort();    all_animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    let list = registry.entry(section.to_string()).or_default();    if !list.iter().any(|s| s == animal) {        list.push(animal.to_string());    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    match registry.get(section) {        Some(animals) => {            let mut result = animals.clone();            result.sort();            result        }        None => Vec::new(),    }}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut animals: Vec<String> = registry        .values()        .flat_map(|value| value.iter().cloned())        .collect();    animals.sort();    animals.dedup();    animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    registry.entry(section.to_string())            .and_modify(|e| {                if let None = e.iter().find(|x| *x == animal) {                    e.push(animal.to_string());                }            })            .or_insert(vec![animal.to_string()]);}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // TODO: implement this function    match registry.get(section) {        Some(animals) => {            let mut result = animals.clone();            result.sort();            result        }        None => Vec::new(),    }}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut result = Vec::new();    for animals in registry.values() {        result.extend(animals.clone());    }    result.sort();    result}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    let animals = registry        .entry(section.to_string())        .or_insert_with(Vec::new);    if !animals.iter().any(|a| a == animal) {        animals.push(animal.to_string());    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let mut animals = registry.get(section).cloned().unwrap_or_default();    animals.sort();    animals}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut animals: Vec<_> = registry.values().cloned().flatten().collect();    animals.sort();    animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section_name: &str, registry: &mut Collection) {    let section = registry        .entry(section_name.to_string())        .or_insert(Vec::new());    if !section.contains(&animal.to_string()) {        section.push(animal.into());    }}pub fn get_animals_in_section(section_name: &str, registry: &Collection) -> Vec<String> {    match registry.get(section_name) {        Some(section) => {            let mut s = section.clone();            s.sort();            s        }        None => vec![],    }}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut animals: Vec<String> = registry        .values()        .flat_map(|value| value.iter().cloned())        .collect();    animals.sort();    animals.dedup();    animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function   let animals = registry.entry(section.to_string()).or_insert_with(Vec::new);    if !animals.iter().any(|a| a == animal) {        animals.push(animal.to_string());    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // TODO: implement this function    match registry.get(section) {        Some(animals) => {            let mut list = animals.clone();            list.sort();            list        }        None => vec![],    }}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut all_animals = Vec::new();    for animals in registry.values() {        all_animals.extend(animals.clone());    }    all_animals.sort();    all_animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    registry.entry(section.to_string())        .and_modify(|list| if !list.contains(&animal.to_string()) { list.push(animal.to_string()) })        .or_insert(vec![animal.to_string()]);        }pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut s = registry        .get(section)        .cloned()        .unwrap_or_default();    s.sort();    s}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut animals: Vec<String> = registry.values().flatten().cloned().collect();    animals.sort();    animals}// use std::collections::HashMap;// type Collection = HashMap<String, Vec<String>>;// pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {//     registry.entry(section.to_string())//         .and_modify(|list| if !list.contains(&animal.to_string()) {  list.push(animal.to_string())})//         .or_insert(vec![animal.to_string()]);// }// pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {//     let mut animals = registry.get(section).cloned().unwrap_or_default();//     animals.sort();//     animals// }// pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {//     let mut animals: Vec<String> = registry.values().flatten().cloned().collect();//     animals.sort();//     animals// }use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    registry.entry(section.to_string())        .and_modify(|list| if !list.contains(&animal.to_string()) {  list.push(animal.to_string())})        .or_insert(vec![animal.to_string()]);}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let mut animals = registry.get(section).cloned().unwrap_or_default();    animals.sort();    animals}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut animals: Vec<String> = registry.values().flatten().cloned().collect();    animals.sort();    animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    let animalc = registry.entry(section.to_string()).or_insert(Vec::new());    if !animalc.contains(&animal.to_string()){        animalc.push(animal.to_string());    }    }pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut result = match registry.get(section){        Some(x) => x.clone(),        None => Vec::new()    };    result.sort();    result}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut resvec = Vec::new();    for animalc in registry.values().into_iter(){        for anim in animalc.into_iter(){            resvec.push(anim.clone());        }    }    resvec.sort();    resvec}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    let coll = registry.entry(section.to_string()).or_insert(Vec::new());    if !coll.contains(&animal.to_string()) {        coll.push(animal.to_string());    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut res = registry.get(§ion.to_string()).cloned().unwrap_or_default();    res.sort();    res}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut res = Vec::new() as Vec<String>;    registry.values().for_each(|animals| animals.iter().for_each(|animal| if !res.contains(&animal.to_string()) {        res.push(animal.to_string());    }));    res.sort();    res}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    let animals = registry.entry(section.to_string()).or_insert(Vec::new());    if !animals.contains(&animal.to_string()){        animals.push(animal.to_string());    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut animals = match registry.get(section){        Some(res) => res.clone(),        None => Vec::new(),    };    animals.sort();    animals    /*let mut animals = match registry.get(section) {        Some(res) => res.clone(),        None => Vec::new()    };    animals.sort();    animals*/}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut result = Vec::new();    for animals in registry.values(){        for a in animals{            result.push(a.to_string());        }    }    result.sort();    result}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    let animals = registry.entry(section.to_string()).or_insert(Vec::new());    if !animals.contains(&animal.to_string()) {        animals.push(animal.to_string());    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut animals = match registry.get(section) {        Some(res) => res.clone(),        None => Vec::new()    };    animals.sort();    animals}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut animals = registry        .values()        .flatten()        .cloned()        .collect::<Vec<String>>();    animals.sort();    animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    let animals = registry.entry(section.to_string()).or_insert(Vec::new());    if !animals.contains(&animal.to_string()) {        animals.push(animal.to_string());    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let mut result = Vec::new();    if let Some(animals) = registry.get(section) {        for a in animals {            result.push(a.to_string());        }        result.sort();    }    result}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut result = Vec::new();    for animals in registry.values() {        for a in animals {            result.push(a.to_string());        }    }    result.sort();    result}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    let res = registry.entry(section.to_string()).or_insert_with(Vec::new);    if !res.contains(&animal.to_string()) {        res.push(String::from(animal));    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let mut animals = match registry.get(section) {        Some(res) => res.clone(),        None => Vec::new(),    };    animals.sort();    animals}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut animals: Vec<String> = registry        .values()        .flatten()        .cloned()        .collect::<Vec<String>>();    animals.sort();    animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    let animals = registry.entry(section.to_string()).or_insert_with(Vec::new);    if !animals.contains(&animal.to_string()) {        animals.push(animal.to_string());    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let mut animals: Vec<String> = registry.get(section).cloned().unwrap_or_else(Vec::new);    animals.sort();    animals}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut all_animals: Vec<String> = registry.values().flatten().cloned().collect();    all_animals.sort();    all_animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    let res = registry.entry(section.to_string()).or_insert(vec![]);    if !res.contains(&animal.to_string()) {        res.push(String::from(animal));    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let mut animals = match registry.get(section) {        Some(res) => res.clone(),        None => Vec::new(),    };    animals.sort();    animals}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut animals: Vec<String> = registry        .iter()        .map(|(_, animals)| animals.clone())        .flatten()        .collect::<Vec<String>>();    animals.sort();    animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    let animals = registry.entry(section.to_string()).or_insert_with(Vec::new);    if !animals.contains(&animal.to_string()) {        animals.push(animal.to_string());    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let mut animals: Vec<String> = registry.get(section).cloned().unwrap_or_else(Vec::new);    animals.sort();    animals}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut all_animals: Vec<String> = registry.values().flatten().cloned().collect();    all_animals.sort();    all_animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    let animals = registry.entry(section.to_string()).or_insert_with(Vec::new);    if !animals.contains(&animal.to_string()) {        animals.push(animal.to_string());    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let mut animals: Vec<String> = registry.get(section).cloned().unwrap_or_else(Vec::new);    animals.sort();    animals}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut all_animals : Vec<String> = registry.values().flatten().cloned().collect();    all_animals.sort();    all_animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    let animals = registry.entry(section.to_string()).or_insert_with(Vec::new);    if !animals.contains(&animal.to_string()) {        animals.push(animal.to_string());    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let mut animals: Vec<String> = registry.get(section).cloned().unwrap_or_else(Vec::new);    animals.sort();    animals}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut all_animals: Vec<String> = registry.values().flatten().cloned().collect();    all_animals.sort();    all_animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    let animals = registry.entry(section.to_string()).or_insert_with(Vec::new);    if !animals.contains(&animal.to_string()) {        animals.push(animal.to_string());    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let mut animals = registry.get(section).cloned().unwrap_or_else(Vec::new);    animals.sort();    animals}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut all_animals: Vec<String> = registry.values().flatten().cloned().collect();    all_animals.sort();    all_animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    let animals = registry.entry(section.to_string()).or_insert_with(||Vec::new());    if !animals.contains(&animal.to_string()){        animals.push(animal.to_string())    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let mut list = registry.get(section).cloned().unwrap_or_default();    list.sort();    list}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut list: Vec<String> = Vec::new();    for (key, value) in registry.iter(){        list.extend(value.iter().cloned());    }    list.sort();    list}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    registry.entry(section.to_string()).and_modify(|sec| { if !sec.contains(&animal.to_string()) { sec.push(animal.to_string()); }  }).or_insert(vec![animal.to_string()]);}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let animals = match registry.get(§ion.to_string()) {        Some(sec) => {            let mut sorted = sec.clone();            sorted.sort();            sorted        },        None => Vec::<String>::new(),    };    animals.to_vec()}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut animals = Vec::<String>::new();    for (_, sec) in registry.iter() {        animals.extend_from_slice(&sec);    }    animals.sort();    animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    if get_animals_in_section(section, registry).contains(&animal.to_string()) {        return;    }    registry        .entry(section.to_string())        .or_default()        .push(animal.to_string())}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let mut values = registry.get(section).cloned().unwrap_or_default();    values.sort();    values}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut animals = registry        .values()        .flat_map(|value| value.clone())        .collect::<Vec<_>>();    animals.sort();    animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    registry        .entry(section.to_string())        .and_modify(|animals| {            if !animals.contains(&animal.to_string()) {                animals.push(animal.to_string())            }        })        .or_insert(vec![animal.to_string()]);}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let mut values = registry.get(section).cloned().unwrap_or_default();    values.sort();    values}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut values = Vec::new();    for (_, value) in registry.iter() {        values.extend_from_slice(value);    }    values.sort();    values}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    let item = registry.entry(section.to_string()).or_insert(Vec::new());    if !item.contains(&animal.to_string()) {        item.push(animal.to_string());    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let mut value = registry.get(section).cloned().unwrap_or_default();    value.sort();    value}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut vecs = vec![];    registry.keys().into_iter().for_each(|x| {        let a = get_animals_in_section(x, registry);        vecs.extend(a);    });    vecs.sort();    vecs}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    let item = registry.entry(section.to_string()).or_insert(Vec::new());     if !item.contains(&animal.to_string()){         item.push(animal.to_string());     }         // item.into_iter().collect(); }pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut animals_in_section = registry.get(section).cloned().unwrap_or_default();    animals_in_section.sort();     animals_in_section}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut all_animals = Vec::new();     for (_, animals) in registry.iter() {        all_animals.extend(animals.clone());     }     all_animals.sort();     all_animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    let current_section = get_animals_in_section(section, ®istry);    if current_section.contains(&String::from(animal)) {        return;    }    registry        .entry(String::from(section))        .or_insert_with(Vec::new)        .push(String::from(animal))}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let mut animals = registry.get(section).cloned().unwrap_or_default();    animals.sort();    animals}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut animals: Vec<String> = registry.values().flat_map(|v| v.clone()).collect();    animals.sort();    animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    let animals = registry.entry(section.to_string()).or_insert_with(Vec::new);    if !animals.iter().any(|a| a == animal) {        animals.push(animal.to_string());    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let mut animals = registry.get(section).cloned().unwrap_or_default();    animals.sort();    return animals;}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut all: Vec<String> = registry        .values()        .flat_map(|animals| animals.iter().cloned())        .collect();    all.sort();    return all;}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    let currentsection = get_animals_in_section(section, registry);    if currentsection.contains(&animal.to_string()){        return;    }       registry        .entry(section.to_string())        .or_insert_with(Vec::new)        .push(animal.to_string());}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let mut animals = registry.get(section).cloned().unwrap_or_default();    animals.sort(); // orden ascendente alfabético    animals}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut all_animals: Vec<String> = registry.values().flat_map(|v| v.clone()).collect();    all_animals.sort();    all_animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    let v = registry.entry(section.into()).or_default();    if !v.contains(&animal.into()) {        v.push(animal.into());    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    if let Some(animals) = registry.get(section) {         let mut copy = animals.to_vec();        copy.sort();        return copy;    }    vec![]}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut all_animals: Vec<String> = registry.values().flatten().cloned().collect();    all_animals.sort();    all_animals}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    if !registry.contains_key(section){        registry.insert(section.to_string(),vec![animal.to_string()]);    }else{        if let Some(vec) = registry.get_mut(section){            if !vec.contains(&animal.to_string()){                vec.push(animal.to_string());            }        }    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // TODO: implement this function    if let Some(val) = registry.get(section){        let mut values = val.to_vec();        values.sort();        return values;    }else{        return vec![];    }}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut values:Vec<String> = registry.values().flatten().cloned().collect();    values.sort();    values}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;// This function should add an animal to a section in the registry. // If the section does not exist, it should be created. // If the animal is already in the section, it should not be added again.pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    //key - section(Arctic, Savannah)    //value - vector of animals    let animals = registry.entry(section.to_string()).or_insert_with(Vec::new);    if !animals.contains(&animal.to_string()){        animals.push(animal.to_string());    }}// This function should return a list of animals sorted alphabetically in a given section. // If the section does not exist, it should return an empty list.pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // TODO: implement this function    if let Some(animals) = registry.get(section){        let mut animals_list = animals.clone();        animals_list.sort();        animals_list    } else{        Vec::new()    }}// This function should return a copy of the entire registry with all animals sorted alphabetically in each section.pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut animals: Vec<String> = registry    .values()    .flat_map(|v| v.clone())    .collect();    animals.sort();    animals    }use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    let mut v = registry.entry(section.into()).or_default(); if !v.contains(&animal.into()) {      v.push(animal.into()); }  }    // TODO: implement this functionpub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    let mut v = registry.get(section.into()).cloned().unwrap_or_default();    v.sort();    v    // TODO: implement this function}    pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    let mut v: Vec<String> = registry.values().flatten().cloned().collect();    v.sort();    v    // TODO: implement this function}use std::collections::HashMap;type Collection = HashMap<String, Vec<String>>;pub fn add_animal_to_section(animal: &str, section: &str, registry: &mut Collection) {    // TODO: implement this function    let mut v = registry.entry(section.into()).or_default();    if !v.contains(&animal.into()) {        v.push(animal.into());    }}pub fn get_animals_in_section(section: &str, registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut v = registry.get(section.into()).cloned().unwrap_or_default();    v.sort();     v}pub fn get_all_animals_sorted(registry: &Collection) -> Vec<String> {    // TODO: implement this function    let mut v: Vec<String> = registry.values().flatten().cloned().collect();    v.sort();     v}// add_animal_to_section: This function should add an animal to a section in the registry. If the section does not exist, it should be created. If the animal is already in the section, it should not be added again.// get_animals_in_section: This function should return a list of animals sorted alphabetically in a given section. If the section does not exist, it should return an empty list.// get_all_animals_sorted: This function should return a copy of the entire registry with all animals sorted alphabetically in each section.