如题,代码如下:
#[derive(Debug)]
enum Mynum<T> {
Clubs(T),
Spades(T),
Diamonds(T),
Hearts(T),
}
impl<T> Mynum<T>{
fn getvalue(self) -> T {
match self{
Mynum::Clubs(v) => v,
Mynum::Spades(v) => v,
Mynum::Diamonds(v) => v,
Mynum::Hearts(v) => v,
}
}
}
fn main() {
let c1 = Mynum::Spades(5);
println!("{:?}",c1.getvalue());
let c1 = Mynum::Hearts("RUST");
println!("{:?}",c1.getvalue());
let c2 = Mynum::Diamonds(99.99);
println!("{:?}",c2.getvalue()+1.0);
}
/*
输出如下内容
5
"RUST"
100.99
*/