Skip to content

Instantly share code, notes, and snippets.

@kriogenia
Created June 3, 2022 13:05
Show Gist options
  • Save kriogenia/9394dea7f599fa3313c52c4d59515586 to your computer and use it in GitHub Desktop.
Save kriogenia/9394dea7f599fa3313c52c4d59515586 to your computer and use it in GitHub Desktop.
Self
struct Foo {
bar: i32
}
impl Foo {
fn instead_of_this() -> Foo {
Foo { bar: 0 }
}
fn you_can_use_this() -> Self {
Self { bar: 0 }
}
}
fn main() {
let a = Foo::instead_of_this();
let b = Foo::you_can_use_this();
assert_eq!(a.bar, b.bar);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment