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
Are you saying public fields could break pattern matching or the getter method would?
1
I think they are saying that making fields private with getters would mean you wouldn't be able to pattern match.
1
Not sure why? you can do a match on the result value of the getter, can’t you?
1
You couldn't do:
Struct { field1, field2: Some(x) } => ...
1
2
Ahhh you can’t do a deconstruction. Makes sense now.
2
If you had a private `_hidden` field you would still be able to do:
Struct { field1, field2: Some(x), ... } => ...
I think it might not allow you to move stuff out though, which is a bummer.
1
2
You *can* move stuff out play.rust-lang.org/?gist=9d95d057
1
5


