You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The readability and maintainability could be greatly improved e.g. by using a builder pattern.
This way, the individuals fields would be more understandable and we could omit the ones where the defaults work.
I had good experiences with derive_builder in the past
Here is an example from their docs:
#[macro_use]externcrate derive_builder;#[derive(Default,Builder,Debug)]#[builder(setter(into))]structChannel{token:i32,special_info:i32,// .. a whole bunch of other fields ..}fnmain(){// builder pattern, go, go, go!...let ch = ChannelBuilder::default().special_info(42u8).token(19124).build().unwrap();println!("{:?}", ch);}
We could use something similar for our Checker:
let checker = Checker::default().token("DUMMY_GITHUB_TOKEN".to_string()).max_redirects(5).user_agent("curl/7.71.1".to_string()).build()?;
This would clean up a lot of lines in our test code and throughout the application.
If anyone wants to tackle this, please add a comment here.
Sorry spoke too soon, i have begun reading rust lang book to learn rust and i though i can handle this but apparently its a bit advanced for my current rust level.
I have done some exploration and looks like rust-typed-builder could be an alternative to derive_builder worth considering.
One caveat I see in our case is that not all fields are trivially instantiated (e.g. reqwest::Client requires using a builder). Having a way to initialize it in the generated build method would be ideal, but I'm not sure if any of these libraries have that capability out of the box.
Not sure if it helps, but according to the docsderive_builder has a flag to skip the build() method:
Build method suppression: You can use #[builder(build_fn(skip))] to disable auto-implementation of the build method and provide your own.
Maybe that's all we need?
@kashifsoofi no worries and thanks for the feedback.
Activity
kashifsoofi commentedon Oct 16, 2020
Can I help on this.
mre commentedon Oct 16, 2020
Sure. It's all yours. Thanks for looking into it. 😊
kashifsoofi commentedon Oct 16, 2020
Sorry spoke too soon, i have begun reading rust lang book to learn rust and i though i can handle this but apparently its a bit advanced for my current rust level.
pawroman commentedon Oct 18, 2020
I have done some exploration and looks like rust-typed-builder could be an alternative to
derive_builderworth considering.One caveat I see in our case is that not all fields are trivially instantiated (e.g.
reqwest::Clientrequires using a builder). Having a way to initialize it in the generatedbuildmethod would be ideal, but I'm not sure if any of these libraries have that capability out of the box.mre commentedon Oct 18, 2020
Not sure if it helps, but according to the docs
derive_builderhas a flag to skip thebuild()method:@kashifsoofi no worries and thanks for the feedback.