djc / imap-proto

IMAP protocol parser and datastructures in Rust
12 stars 2 forks source link

Private fields in `Response` type: how to get at contents? #14

Open sanmai-NL opened 6 years ago

sanmai-NL commented 6 years ago

E.g.: field `0` of tuple-struct `imap::Capabilities` is private. I couldn’t find getters or so for these fields. IMO, the fields in public types should just be public too. (The crate does not have a stable API and needs to be used in practice before even considering adding a lot of ceremony like getters.)

sanmai-NL commented 6 years ago

Hm, it appears in mattnenterprise/rust-imap#58 another type was added with the same name (Capabilities, pub struct Capabilities(pub(crate) HashSet<&'static str>);), and it can somehow access the innards of this type in https://github.com/mattnenterprise/rust-imap/blob/5a3ee10b18a2f01e4c14c3982294d53b9a92997c/src/parse.rs#L108-L130 .

djc commented 6 years ago

Yeah, it seems to me that you can usually get at the contents by just matching against it.

I'm not sure about making fields public. The API guidelines state that things should be private with getters so that you can change implementation details without necessarily changing the API.