Search
 
SCRIPT & CODE EXAMPLE
 

RUST

rust dictionary

// Rust does not include dict in its std library.
// You can use `hashmap`

use std::collections::Hashmap;

fn main() {
	let x = Hashmap::from(["a", "foo"], ["b", "bar"]);
    
    println!("{}", x["a"]);
    
    // If you don't like the above syntax you can create a macro:
    macro_rules! dict {
    	{$($key:ident => $value:expr),*} => {
        	{
              let mut temp = Hashmap::new();
              $(
              temp.insert(stringify!($key), $value);
              )*
              
              temp
            }
        };
    }
    
    let y = dict! {
    	a => "foo",
        b => "bar"
    };
    
    println!("{}", y["a"]);
}
Comment

PREVIOUS NEXT
Code Example
Rust :: hello world rust 
Rust :: how to index a string in rust 
Rust :: rust field is never read remove warning 
Rust :: array as a parameter rust 
Rust :: convert string to i32 rust 
Rust :: rust size of type 
Rust :: get length of string rust 
Rust :: range in rust 
Rust :: host rust server 
Rust :: actix web hello world 
Rust :: find last element of vec rust 
Rust :: const generics in rust 
Rust :: armanriazi•rust•pattern•design•interior•mutability 
Rust :: check if a string contains consecutive letters that occur only once 
Rust :: armanriazi•rust•error•[E0308]: mismatched types expected integer, found floating-point number 
Rust :: armanriazi•rust•interior-mutability•vs•inherited-mutability 
Rust :: rust missing lifetime specifier 
Rust :: armanriazi•rust•error•[E0782]: trait objects must include the `dyn` keyword 
Rust :: armanriazi•rust•concept•memoization•lazy•evaluation 
Rust :: rust how to create array with the same value 
Rust :: rust•armanriazi•concept•nan 
Lua :: lua how to get random object from a table 
Lua :: roblox kill brick script 
Lua :: open gui script 
Lua :: keywords in lua 
Lua :: prompt developer product purchase roblox 
Lua :: lua toggle 
Lua :: lua string replace 
Lua :: lua difference between pairs and ipairs 
Lua :: convert a float to string lua 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =