Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUST

Vector with multiple types in rust

enum Thing {
    Op(Operator),
    Number(i32),
}

fn main() {
    let mut output: Vec<Thing> = Vec::new();
    let a = 2;
    let b = Operator::Add;
    let c = 3;
    output.push(Thing::Number(a));
    output.push(Thing::Op(b));
    output.push(Thing::Number(c));
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Vector #multiple #types #rust
ADD COMMENT
Topic
Name
4+3 =