-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Create a more rigid overseer builder pattern that fails at compile time #4753
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start! It requires some additional attention on the way things are represented, and - as you already said - a round of cleanups.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superficial pass
`subsyste_ctx_name` actually masked `subsystem_ctx_name` and it seems that only the former one is really needed
This is used to pretty format placeholder types names
)* | ||
}; | ||
quote! { | ||
impl <InitStateSpawner, #additional_baggage_generic #( #subsystem_passthrough_state_generics, )* #( #impl_baggage_state_generics, )* > |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and add it here instead
let subsystem_string = String::from(stringify!(#subsystem_name)); | ||
// Convert owned `snake case` string to a `kebab case` static str. | ||
let subsystem_static_str = Box::leak(subsystem_string.replace("_", "-").into_boxed_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note to myself: this could be extracted as generated &'static str
rather than the adhoc string generation and leaking it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few micro nits that need to be addressed, other than that 👍
This pull requests addresses #3772
The general idea is to generalise all fields arguments and fix them in two states:
Uninit<T>
for uninitialised fieldsInit<T>
for initialised fieldsWith this approach, each setter function accepts builder template with
Uninit<Field>
and returns a builder where this field is changed toInit<Field>
. Subsequentlybuild
function accepts all templated fields to beInit<T>
and fails to compile if any of the required fields is missing.