3 ms·
Largely unrelated question: In the code about a third of the way into the article, there is, impl<'a> Drop for Foo<'a> { fn drop(&mut self) {
by mcguire 12y ago
Largely unrelated question: In the code about a third of the way into the article, there is,
impl<'a> Drop for Foo<'a> {
fn drop(&mut self) {
*self.0 += 1;
}
}
What does the line "self.0 += 1;" do? Specifically, the ".0"? Foo is a basically a reference to an i32, so I would have thought that would be "self += 1;".
- steveklabnik 12y agoThe .0 is a tuple access. Foo is a 'tuple struct' of length 1: http://doc.rust-lang.org/nightly/book/tuple-structs.html http://doc.rust-lang.org/nightly/book/tuple-structs.html (though the syntax is explained in the section on tuples: http://doc.rust-lang.org/nightly/book/primitive-types.html#tuple-indexing http://doc.rust-lang.org/nightly/book/primitive-types.html#t... )
- mcguire 12y agoAh! Cool. Thanks!