Created
January 16, 2018 18:06
-
-
Save Ph0enixKM/0e51edfcb989b756f13b89be2d5f9471 to your computer and use it in GitHub Desktop.
Rusty Invalid Enum
This file contains 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
fn main() { | |
#![allow(unused_variables)] | |
#[derive(Debug)] | |
enum Message { | |
Quit, | |
Write(String), | |
} | |
impl Message { | |
fn call(&self) { | |
// I want to take a value of Write(String) | |
match &self { | |
&Write(x) => println!("{:?}", x ), | |
&Quit => println!("err"), | |
} | |
} | |
} | |
let m = Message::Write(String::from("hello")); | |
m.call(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment