3 ms·
can someone explain what the self.0 means? im not a rust speaker
by Surac 3mo ago
can someone explain what the self.0 means? im not a rust speaker
- csande17 3mo agoRust has a feature called "tuple structs" where the properties of the struct are accessed by numeric indices instead of names: https://doc.rust-lang.org/book/ch05-01-defining-structs.html#creating-different-types-with-tuple-structs https://doc.rust-lang.org/book/ch05-01-defining-structs.html... / https://doc.rust-lang.org/book/ch05-02-example-structs.html#refactoring-with-tuples https://doc.rust-lang.org/book/ch05-02-example-structs.html#... In most other languages this would be written as "this.current_index" or some other property name.
- tialaramex 3mo agoself.0 is the zeroth field of self, self is the name for a value of this type, apparently a type named LexerConsumer, this function took "&mut self" a mutable reference to a LexerConsumer. In Rust using any variety of "self" in this way means the function can (if you want) be called as a method on a LexerConsumer like this: foo.consume(); // If foo is a LexerConsumer, we will call that `consume` function and pass it a mutable reference to foo. Presumably the LexerConsumer doesn't give its fields names, so hence self.0 meaning just the zeroth field. Perhaps the author couldn't think of a good name for it.