Should the associated function options become a common API convention?
#260
Enet4
started this conversation in
API Guidelines
Replies: 2 comments
|
"options" is a somewhat idiosyncratic name for what it is: a builder. For types Foo and FooBuilder, yes, I think it is nice to have a Foo::builder method. I personally plan to add such a thing to most or all of my crates, but just haven't actually done it yet. |
0 replies
|
I argue a trait could be useful on this matter: trait Builder {
type Builder;
fn builder() -> Self::Builder;
}It's very simple and some could say it's useless, but it's allow documentation easy thing and set a more clear convention. I'm opposed to use |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
The function
File::optionswas stabilized in Rust 1.58 (rust-lang/rust#65439). The arguments given for this function to exist is that it's syntactic sugar forOpenOptions::new()that does not require importingOpenOptions.rust-lang/rust#65439 (comment)
This raises the question: for other builder types of the
FooOptionsform, should it become idiomatic for Rust code to also add an associated functionFoo::options()that is equivalent in behavior asFooOptions::new(), and how would it be encoded as a guideline? This does not appear to be something ubiquitous at this time, but the introduction of this pattern instdcreates a precedent.All reactions