How to declare and initialize a set containing unique objects in Rust

1 Answer

0 votes
use std::collections::HashSet;

fn main() {
    let mut st = HashSet::new();
    
    st.insert("a");
    st.insert("b");
    st.insert("c");
    st.insert("d");

    println!("{:?}", st);
}




/*
run:

{"a", "d", "c", "b"}

*/

 



answered Mar 11, 2023 by avibootz

Related questions

...