Have a question: does the slice have any extra data for example zero at the end of the string or size of the string at the beginning of the string?
In this code:
use std::collections::HashMap;
fn main()
{
let mut hashmap : HashMap< &'static str, &'static str > = HashMap::new();
hashmap.insert( "EUR", "Euro" );
hashmap.insert( "USD", "US Dollar" );
hashmap.insert( "CHF", "Swiss Francs" );
let usd = hashmap.get( "EUR" );
if let Some( usd ) = usd
{
println!( "usd : {}", usd );
}
// < usd : US Dollar
}
Key as well as the value of the HashMap let mut hashmap : HashMap< &'static str, &'static str >
could have any length. Right? I don't understand how does the program knows US Dollar
has length/size of 9? Does the slice have any extra data for example zero at the end of the string or size of the string at the beginning of the string?
Playground is here.