8 ms·
In Rust you usually use either method chaining (CustomObject::new(param1, param2).option15('bar')) or the struct update syntax (CustomObject { param1: param1, p
by pcwalton 11y ago
In Rust you usually use either method chaining (CustomObject::new(param1, param2).option15('bar')) or the struct update syntax (CustomObject { param1: param1, param2: param2, option15: 'bar', ..DEFAULT_CUSTOM_OBJECT }) for this. No extra complexity of "zero values" necessary (and the concept of a zero value would be incoherent in Rust anyway).
- tracker1 11y agoBut you have either the complexity of multiple closures, or complex mutability (side effects) with that strategy, depending on how you approach your implementation. In either case the outcome could be less than ideal, and have more chance of unexpected results. Is this... var obj = new CustomObject(...); ... obj.option15('bar'); The same as var obj = new CustomObject(...).option15('bar'); IE: does calling option15 create a new closure/space that is separate from the original object (more functional separation) or does it mutate the original object? I tend to prefer to limit mutations as much as possible in my code... it really just depends on your needs.
- Jweb_Guru 11y agoThere is neither mutability nor multiple closures involved in the record update syntax.