Closed skywhale closed 3 years ago
The builder pattern actually seems like the right approach here. I also wouldn't worry about needless clones for initialization code.
The API you've prototyped here seems pretty reasonable and is definitely an improvement over the current situation.
I agree with @bschwind. With modern IDE integration, a builder pattern could provide a more straightforward coding experience, without having to internalize all the function variants.
+1, builder pattern looks great here.
Current state (with docs tweaks):
There are 3 independent aspects (capacity or not, direct or factory, explicit vs. implicit address) that together create combinatorial explosion.
For the direct or factory aspect, I don't see any better alternative than a pair of functions. Stdlib with funs like
or()
,or_else()
is the precedent here.The "generic" solution to this is a builder pattern (which I haven't fallen in love with). How would that look like?
...not that bad?
#[must_use]
could prevent folks from forgetting to call.spawn()
. All names subject to bikeshedding.If we decide to approach the builder pattern:
system.spawn(actor)
shorthand? (yes)system.spawn_fn(|| factory())
shorthand? (no)system.prepare(actor)
in addition tosystem.prepare_fn(|| factory())
? (yes?)