In Rust, you can use a HashMap to create a key-value store. To get the value associated with a key, you can use the HashMap::get
function.
main.rs341 chars15 lines
In the code block above, we first create a new HashMap and insert key-value pairs. We then use the HashMap::get
function to retrieve the value associated with "one". The function returns an Option, which we then match on to check if the key was found. If the key was found, we print the value. If not, we print a message saying that the key was not found.
gistlibby LogSnag