rust 1.77 Debugging a hashMap with string results in an error #40
Replies: 4 comments 2 replies
-
Hey @zxhd863943427, thanks for the report! I'm investigating it :) |
Beta Was this translation helpful? Give feedback.
-
Hey @zxhd863943427, please check #41 |
Beta Was this translation helpful? Give feedback.
-
Released 1.77.1 to fix it. |
Beta Was this translation helpful? Give feedback.
-
I apologize for not checking this discussion in the past two weeks. It's hard to imagine there would be a response so quickly. Thank you for your outstanding work! The original minimal reproducible example has been fixed, but a new issue has emerged in the complete code. Here is a more comprehensive minimal reproducible code snippet. use std::collections::{HashMap};
use std::fmt;
pub struct UndirectedGraph {
adjacency_table: HashMap<String, Vec<(String, i32)>>,
}
impl UndirectedGraph {
fn new() -> UndirectedGraph {
UndirectedGraph {
adjacency_table: HashMap::new(),
}
}
fn adjacency_table_mutable(&mut self) -> &mut HashMap<String, Vec<(String, i32)>> {
&mut self.adjacency_table
}
fn add_edge(&mut self, edge: (&str, &str, i32)) {
//TODO
let table = self.adjacency_table_mutable();
match table.get_mut(edge.0) {
None=>{
table.insert(edge.0.to_string(), vec![(edge.1.to_string(),edge.2)]);
}
Some(values)=>{
values.push((edge.1.to_string(),edge.2));
}
};
match table.get_mut(edge.1) {
None=>{
table.insert(edge.1.to_string(), vec![(edge.0.to_string(),edge.2)]);
}
Some(values)=>{
values.push((edge.0.to_string(),edge.2));
}
}
}
}
#[cfg(test)]
mod test_undirected_graph {
use super::UndirectedGraph;
#[test]
fn test_add_edge() {
let mut graph = UndirectedGraph::new();
graph.add_edge(("a", "b", 5));
graph.add_edge(("b", "c", 10));
graph.add_edge(("c", "a", 7));
}
} The full code can be found at: https://github.com/LearningOS/rust-rustlings-2024-spring-zxhd863943427/blob/main/exercises/algorithm/algorithm10.rs Thank you once again for your outstanding work! |
Beta Was this translation helpful? Give feedback.
-
Hello guys! Thank you for making this excellent tool! I'm learning rust and it has been a great help to me. It runs well most of the time, except for some parts involving hashMap.
Here is a minimally reproducible example:
It will trigger the following error:
Is there anything I can do to help fix this? Thanks again!
Beta Was this translation helpful? Give feedback.
All reactions