Created
June 3, 2022 13:05
-
-
Save kriogenia/9394dea7f599fa3313c52c4d59515586 to your computer and use it in GitHub Desktop.
Self
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 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