Hashmaps are one of the most versatile data structures in Rust, providing a way to store key-value pairs. They are part of the standard library and offer a convenient way to associate values with unique keys. In this challenge, you will implement a simple key-value store using Rust's HashMap
.
The HashMap
type is part of the std::collections
module and allows you to perform operations such as inserting, retrieving, and removing elements efficiently.
You are tasked with implementing two functions for a key-value store:
insert_or_update
: Inserts a new key-value pair into the HashMap
, or updates the value if the key already exists.get_value
: Retrieves a value by its key. If the key is not present, return None
.You will write both functions to work with a HashMap<String, String>
.
HashMap<String, String>
, a key of type String
, and a value of type String
.HashMap<String, String>
and a key of type String
.Option<String>
:
Some(value)
if the key is present.None
if the key is absent.HashMap
type from std::collections
..insert()
method of HashMap
..get()
method of HashMap
.