Created
June 12, 2019 12:47
-
-
Save rust-play/f0125ec3b84d8cfa906aee9fb368f710 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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
struct S { | |
data: Option<String> | |
} | |
impl S { | |
fn data(&self) -> String { | |
if let Some(ref data) = self.data { | |
data.clone() | |
} else { | |
panic!() | |
} | |
} | |
} | |
fn main() { | |
let s = S{ data: Some(String::from("foobar")) }; | |
dbg!(s.data()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment