-
-
Save rust-play/38928f63a53570cdbe184fa6c971c911 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
#[derive( PartialEq, Debug, Clone, Default)] | |
pub struct Thing { | |
name: String, | |
number: i32, | |
} | |
impl Thing { | |
fn new(name: &str, number: Option<i32>) -> Thing { | |
Thing { | |
name: name.to_string(), | |
number: number.unwrap_or_default(), | |
} | |
} | |
} | |
fn main() | |
{ | |
let mut thing_vector = vec![]; | |
thing_vector.push(Thing::new("John Doe", Some(37))); | |
thing_vector.push(Thing::new("Jill Doe", None)); | |
for pl in &mut thing_vector { | |
println!("{} {}", pl.name, pl.number); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment