I'm trying to decide which variant works better:
impl Foo {
pub fn make(...) -> Self {
Self { ... }
}
}
or
pub fn make_foo(...) -> Foo {
Foo { ... }
}
The advantage of having associated functions is that the documentation makes it easy to find (especially if a module has multiple structs, where all the free functions would be mixed together). But the downside is that you cannot import make
directly, it has to be used as Foo::make
. Whereas with make_foo
, you could easily import and rename it as needed.
Are there other reasons to prefer the associated function (or avoid the free function)? If so, is there a workaround for being unable to import the function directly, or is it usually just not a big deal to spell out the full name of the function?