Inherent method wrappers around traits #147
ExpHP
started this conversation in
API Guidelines
Replies: 1 comment
-
I was probably going to wait to find examples before posting this but unfortunately I fat-fingered the "Post" button. Anyways, I'm done fixing it up, so perhaps others can share their thoughts on whether such a guideline is needed. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I often feel like it is a design mistake when it is necessary to import a trait in order to use methods of a type (defined in the same crate) that seem like they should be inherent. Or perhaps, when it seems reasonable that people would want to use the method in non-generic contexts.
In this case, one can internally use a macro to generate inherent methods for each type that wraps the methods. (note: I looked around and haven't explicitly found an example of this yet; maybe this is just my own pet solution)
I'm not sure on the precise guidelines, but I believe some possible signs that a trait's impls should be wrapped with inherent methods are:
(actually, these are all signs that a trait should not be public in the first place; but perhaps it is exposed for the sake of a free function)
Without a clear guideline, I think what this really needs at this point is just discussion.
Beta Was this translation helpful? Give feedback.
All reactions