Skip to content

Instantly share code, notes, and snippets.

@anupam-io
Created March 24, 2022 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anupam-io/a1dc280d8faa26bad973ae8fd435bae8 to your computer and use it in GitHub Desktop.
Save anupam-io/a1dc280d8faa26bad973ae8fd435bae8 to your computer and use it in GitHub Desktop.
Match statement bug
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