Skip to content

Instantly share code, notes, and snippets.

@quake
Created October 28, 2019 03:05
Show Gist options
  • Save quake/fa507070c99bad4571ca324dc9e9ec88 to your computer and use it in GitHub Desktop.
Save quake/fa507070c99bad4571ca324dc9e9ec88 to your computer and use it in GitHub Desktop.
fn foo(foo: u32) -> u32 {
println!("foo {}", foo);
foo + 1
}
#[derive(Debug)]
struct Bar {
bar1: u32,
bar2: u32,
bar3: u32,
}
impl Default for Bar {
fn default() -> Self {
Self {
bar1: foo(1),
bar2: 0,
bar3: 0,
}
}
}
impl Bar {
pub fn with_bar1(bar1: u32) -> Self {
Self {
bar1,
..Default::default()
}
}
}
fn main() {
let bar = Bar::with_bar1(3);
println!("bar {:?}", bar);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment