afero
afero copied to clipboard
Make constructors return structs instead of interfaces
This changes the return type of the various NewXxxx functions from Fs to the relevant type that's being returned.
To maintain the same level of compile-time checking, each type impacted now has a var _ Fs = (*TheType)(nil) no-op assignment to assert that the type implements Fs.
This change brings afero more in line with the "accept interfaces, return structs" idiom.
Importantly, this makes the constructor functions easier to discover in GoDoc since they will now be grouped with the structs that they build.
AFAIK, this should be completely backwards compatible despite changing the API because:
- The values are still assignable to
Fs - Interfaces are transparent to reflection
Edit: I suppose this would be a breaking change if anybody assigned the constructor to a value. Seems unlikely, but plausible. Would that require a major version bump?
Edit 2: This also breaks any code that performs a type assertion on the returned value (by making the assertion unnecessary).
Fixes https://github.com/spf13/afero/issues/76
Be great to see this land