< 返回版块

九世 发表于 2018-07-26 11:36

Tags:Rust问答

fn main(){ enum Sprean{ Int(i32), Float(f64), Text(String), }

let row=vec![
    Sprean::Int(3),
    Sprean::Float(10.12),
    Sprean::Text(String::from("blue")),
];

println!("This is your {}",row[0]);

}

评论区

写评论
idle 2018-08-14 01:40

也可以用这种方法

#[derive(Debug)]
enum Sprean {
    Int(i32),
    Float(f64),
    Text(String),
}
fn main() {
    let row = vec![
        Sprean::Int(3),
        Sprean::Float(10.12),
        Sprean::Text(String::from("blue")),
    ];

    println!("This is your {:?}", row[1]);
}
idle 2018-08-14 01:39

也可以用这种方法

#[derive(Debug)] enum Sprean { Int(i32), Float(f64), Text(String), } fn main() { let row = vec![ Sprean::Int(3), Sprean::Float(10.12), Sprean::Text(String::from("blue")), ];

println!("This is your {:?}", row[1]);

}

123hc 2018-07-27 23:22

还有可以使用match

@九世 Thanks♪(・ω・)ノ

@123hc enum Sprean{ Int(i32), Float(f64), Text(String), } fn main(){ let row=vec![ Sprean::Int(3), Sprean::Float(10.12), Sprean::Text(String::from("blue")), ]; if let Sprean::Int(x) =row[0]{ println!("This is your {}",x); } }

作者 九世 2018-07-27 13:00

Thanks♪(・ω・)ノ

@123hc enum Sprean{ Int(i32), Float(f64), Text(String), } fn main(){

let row=vec![ Sprean::Int(3), Sprean::Float(10.12), Sprean::Text(String::from("blue")), ];

if let Sprean::Int(x) =row[0]{ println!("This is your {}",x); } }

作者 九世 2018-07-27 12:59

Thanks♪(・ω・)ノ

123hc 2018-07-26 19:02
enum Sprean{ 
    Int(i32),
    Float(f64), 
    Text(String), 
}
fn main(){ 

let row=vec![
    Sprean::Int(3),
    Sprean::Float(10.12),
    Sprean::Text(String::from("blue")),
];

if let Sprean::Int(x) =row[0]{
        println!("This is your {}",x);
    }
}
bluesky 2018-07-26 17:21

#[derive(Debug)] enum Sprean { Int(i32), Float(f64), Text(String), } fn main() { let row=vec![ Sprean::Int(3), Sprean::Float(10.12), Sprean::Text(String::from("blue")), ]; println!("This is your {:?}",row[0]); }

bluesky 2018-07-26 17:21

run了一下上面的,有点问题,发一个可以run的

#[derive(Debug)] enum Sprean { Int(i32), Float(f64), Text(String), } fn main() { let row=vec![ Sprean::Int(3), Sprean::Float(10.12), Sprean::Text(String::from("blue")), ]; println!("This is your {:?}",row[0]); }

bluesky 2018-07-26 17:19

run了一下上面的,有点问题,发一个可以run的

#[derive(Debug)] enum Sprean{ Int(i32), Float(f64), Text(String), } fn main() { let row=vec![ Sprean::Int(3), Sprean::Float(10.12), Sprean::Text(String::from("blue")), ]; println!("This is your {:?}",row[0]); }

bluesky 2018-07-26 17:18

run了一下上面的,有点问题,发一个可以run的

#[derive(Debug)] enum Sprean{ Int(i32), Float(f64), Text(String), }

fn main() { let row=vec![ Sprean::Int(3), Sprean::Float(10.12), Sprean::Text(String::from("blue")), ];

println!("This is your {:?}",row[0]);

}

bluesky 2018-07-26 17:16

run了一下上面的,有点问题,发一个可以run的

#[derive(Debug)] enum Sprean{ Int(i32), Float(f64), Text(String), }

fn main() { let row=vec![ Sprean::Int(3), Sprean::Float(10.12), Sprean::Text(String::from("blue")), ];

println!("This is your {:?}",row[0]); }

1 共 11 条评论, 1 页