Created
March 24, 2022 20:53
-
-
Save anupam-io/a1dc280d8faa26bad973ae8fd435bae8 to your computer and use it in GitHub Desktop.
Match statement bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use cosmwasm_std::{from_binary, to_binary, Binary}; | |
use serde::{Deserialize, Serialize}; | |
#[derive(Serialize, Deserialize)] | |
enum Cars { | |
Audi { id: u32, number_plate: u32 }, | |
Bmw { id: u32, number_plate: u32 }, | |
} | |
#[derive(Serialize, Deserialize)] | |
enum Bikes { | |
Yamaha { id: u32, number_plate: u32 }, | |
Bajaj { id: u32, number_plate: u32 }, | |
} | |
fn buy(prop: Binary) { | |
match from_binary(&prop).unwrap() { | |
Cars::Audi { id, number_plate } => { | |
println!("{:?}", (id, number_plate)); | |
} | |
_ => {} | |
} | |
match from_binary(&prop).unwrap() { | |
Bikes::Yamaha { id, number_plate } => { | |
println!("{:?}", (id, number_plate)); | |
} | |
_ => {} | |
} | |
} | |
fn main() { | |
let x = Cars::Audi { | |
id: 0, | |
number_plate: 1, | |
}; | |
let y = Bikes::Yamaha { | |
id: 0, | |
number_plate: 1, | |
}; | |
buy(to_binary(&x).unwrap()); | |
buy(to_binary(&y).unwrap()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment