Methods can be chained in Rust paying attention on fulfilling the ownership rules. For example: functions that return a void valued cannot be chained because when the function ends it drops the values from the memory preventing to have a dangling reference.
The rest of the combinations are derive because you can have only 1 mutable reference and N immutable of the same struct. In general terms methods can be chained like:
Function return | self | &self | $mut self |
---|---|---|---|
( ) | ❌ Not allowed | ❌ Not allowed | ❌ Not allowed |
Self | ✅ Ok | ✅ Ok | ✅ Ok |
&Self | ❌ Not allowed | ✅ Ok | ❌ Not allowed |