-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes to Activity
design
#22
Comments
Sorry for the very late response 😅 About the builder patern, check derive_builder if you're not using it yet About boilerplate, would a impl of .timestamps(activity::Timestamps::from((Some(1), None)) which imo is not that bad |
Hey, appreciate any response at all 😄!
I've checked out that crate, and I really like what it does! My goal is to take design cues from the generated builders in the final product, absolutely. I'm slightly hesitant on including it as a dependency though, since it's not a difficult implementation, and I'd like to keep the crate relatively lean.
I really like this! It would make it a lot easier to construct these smaller models without tons of chained calls. Do you think this would be a good thing to implement alongside the verbose option (like how I constructed the Thanks again for the response! |
Late again 😅
Yes! That would be preferable imo. |
Alright, sounds good! |
This is a good idea! I've been using this crate in my project for a while and I have been struggling with exactly this problem of ownership when trying to build an activity. My current code for getting around this issue is very messy so having this fixed would be awesome! |
Same with party it could be: .timestamps(activity::Party::new( Some("some-id"), Some([1,3]) )); |
Implementing From allows us to use But yea it would be cool to add this pattern for every method |
i'll plan to implement this pattern for every method :) (except for where it makes no sense to do so) |
Some recent issues have brought up some concerns with the current structure of the
Activity
struct and the way it works. I'm currently working on re-designing these interfaces to address these issues and hopefully be overall easier to use. These changes are heavily breaking and would/will accompany a future major version update.Changes
My current idea is to separate the current usage flow into distinct
Activity
andActivityBuilder
structs, implementing a consuming builder design pattern. My working design for this would look something like this in practice:This showcases several things:
ActivityBuilder
structs support chaining similar to that of the current design.build()
must be chained (or a new reference has to be created for each setter called)Activity
structs now haveset_*
methods which take an&mut self
. This makes it much easier to update individual model values after the model has been built (Useless lifetimes #19)Unrelated to the updates to chaining and construction, none of the library's models require lifetimes anymore, and accept anything that satisfies
impl ToString
where an&str
was previously required - which was the reason the lifetimes were previously in place (also #19).Discussion
I'm raising this issue to get feedback about the design as I've presented it, and if there are improvements to be had.
My main concern is the added boilerplate. I don't think it's a big issue for the large
ActivityBuilder
, since that's already a pretty long chain in practice, but as seen in the example code above, it definitely uglifies lines such asIs this beyond the acceptable amount of boilerplate, are there alternative solutions? One idea I scrapped was adding simple
::new
functions for models likeTimestamps
instead of implementing a builder - the issue here is that this would then require arguments to be passed in anOption
-friendly form, which still adds boilerplate.This was a lot of words, so I thank any who read them all, and I'd appreciate feedback/discussion :)
The text was updated successfully, but these errors were encountered: