-
Notifications
You must be signed in to change notification settings - Fork 46
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
feature: builder pattern for application #107
Comments
This would be a good extension to the API. It would also make sense to provide a wrapper function around
Yes, we can then discuss the proposed builder pattern in more detail. |
Yeah, that's also kind ugly and repetitive. Ideally, the following: CharacteristicWriteMethod::Fun(Box::new(move |new_value, req| {
async move {
todo!("{:?} {:?}", new_value, req);
}
.boxed()
})), Could be written as: CharacteristicWriteMethod::from(async move {
todo!("{:?} {:?}", new_value, req);
}), However, async closures are unstable: rust-lang/rust#62290. I used I'm not sure that there's anything actionable on simplifying |
You don't need async closures for that. You can create a wrapper function like this:
|
Creating an
Application
instance is pretty noisy:All these
Default::default
add lot of noise to reading the code (I'm pretty sure the compiler actually optimised away all the intermediate variables being created here).After writing a small application using this type, I have a strong impression that a much better API could be provided by using a builder pattern:
Note how this approach also makes some fields mandatory (e.g.: the
uuid
toApplication
must be provided). Aside fromwith_primary_characteristic
, theServiceBuilder
also has awith_characteristic
for non-primary ones.A longer (fictitious) example:
Is there any interest in having such builders? I'd start out with the inner ones (e.g.:
Characteristic::builder
) and progressively add the higher one.The text was updated successfully, but these errors were encountered: