You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: 0347-top-k-frequent-elements.rs
    path of file: ./repos/NeetCode-Solutions/01_Arrays_&_Hashing/05_Top_K_Frequent_Elements
    
    the code of the file until where you have to start completion: /*
Problem: LeetCode 347 - Top K Frequent Elements

Key Idea:
The key idea is to use a combination of a hashmap to count the frequency of each element and a min heap (priority queue) to efficiently mai
    
    pub fn top_k_frequent(nums: Vec<i32>, k: i32) -> Vec<i32> {
        let mut freq_map: HashMap<i32, i32> = HashMap::new();

        // Count the frequency of each element
        for num in &nums {
            *freq_map.entry(*num).or_insert(0) += 1;
        }

        // Create a min heap of size k to store the top k frequent elements
        let mut min_heap: BinaryHeap<Reverse<(i32, i32)>> = BinaryHeap::new();

        // Insert elements into the heap
        for (num, freq) in freq_map.iter() {
            if min_heap.len() < k as usize {
                min_heap.push(Reverse((*freq, *num)));
            } else if freq > &min_heap.peek().unwrap().0 .0 {
                min_heap.pop();
                min_heap.push(Reverse((*freq, *num)));
            }
        }

        // Extract the elements from the heap
        let result: Vec<i32> = min_heap.into_iter().map(|rev| rev.0 .1).collect();

        result
    }