When building #rustlang libraries, and you have result payloads (structs), is it more idiomatic to expose public struct fields or to create getter methods?
Conversation
if the only thing that struct is for is returning, the public fields is better.
also, bear in mind, with public fields, you can move out of the struct.
1
2
That makes sense. The structs are basically serialization anchors for JSON going to and from a REST endpoint. Thinking of using builder pattern to create and just pub immutable fields for read
1
1
Note that public fields can make it hard to update an API without bumping a version (folks might be pattern matching on it). Having a single private field could solve that.


