mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 11:41:02 +00:00
feat/overseer: introduce closure init (#3775)
* feat/overseer: introduce closure init Enables removal of the connected/disconnected overseer state. * feat/overseer: allow replacement logic to access the original Allows to re-use init-once types, which would otherwise error. * feat/overseer: introduce external connector Preparation for removal of `AllSubsystems` which is another prerequisite for removing the connect/disconnect state. * fix/test: replace needs closure * fixup * simplify * mea culpa * all-subsystems-gen test
This commit is contained in:
committed by
GitHub
parent
5596170bfb
commit
3cc5a1eee9
@@ -118,10 +118,11 @@ fn impl_subsystems_gen(item: TokenStream) -> Result<proc_macro2::TokenStream> {
|
||||
|
||||
// generate an impl of `fn replace_#name`
|
||||
for NameTyTup { field: replacable_item, ty: replacable_item_ty } in replacable_items {
|
||||
let keeper = all_fields
|
||||
let keeper = &all_fields
|
||||
.iter()
|
||||
.filter(|ntt| ntt.field != replacable_item)
|
||||
.map(|ntt| ntt.field.clone());
|
||||
.map(|ntt| ntt.field.clone())
|
||||
.collect::<Vec<_>>();
|
||||
let strukt_ty = strukt_ty.clone();
|
||||
let fname = Ident::new(&format!("replace_{}", replacable_item), span);
|
||||
// adjust the generics such that the appropriate member type is replaced
|
||||
@@ -154,11 +155,27 @@ fn impl_subsystems_gen(item: TokenStream) -> Result<proc_macro2::TokenStream> {
|
||||
additive.extend(quote! {
|
||||
impl #orig_generics #strukt_ty #orig_generics {
|
||||
#[doc = #msg]
|
||||
pub fn #fname < NEW > (self, replacement: NEW) -> #strukt_ty #modified_generics {
|
||||
pub fn #fname < NEW, F > (self, gen_replacement_fn: F) -> #strukt_ty #modified_generics
|
||||
where
|
||||
F: FnOnce(#replacable_item_ty) -> NEW,
|
||||
{
|
||||
let Self {
|
||||
// To be replaced field:
|
||||
#replacable_item,
|
||||
// Fields to keep:
|
||||
#(
|
||||
#keeper,
|
||||
)*
|
||||
} = self;
|
||||
|
||||
// Some cases require that parts of the original are copied
|
||||
// over, since they include a one time initialization.
|
||||
let replacement = gen_replacement_fn(#replacable_item);
|
||||
|
||||
#strukt_ty :: #modified_generics {
|
||||
#replacable_item: replacement,
|
||||
#(
|
||||
#keeper: self.#keeper,
|
||||
#keeper,
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,5 +12,5 @@ fn main() {
|
||||
a: 0_u16,
|
||||
b: 1_u16,
|
||||
};
|
||||
let _all = all.replace_a(77u8);
|
||||
let _all = all.replace_a(|_| 77u8);
|
||||
}
|
||||
|
||||
@@ -10,5 +10,5 @@ error[E0599]: no method named `replace_a` found for struct `AllSubsystems<u16>`
|
||||
5 | struct AllSubsystems<X> {
|
||||
| ----------------------- method `replace_a` not found for this
|
||||
...
|
||||
15 | let _all = all.replace_a(77u8);
|
||||
15 | let _all = all.replace_a(|_| 77u8);
|
||||
| ^^^^^^^^^ method not found in `AllSubsystems<u16>`
|
||||
|
||||
@@ -13,5 +13,5 @@ fn main() {
|
||||
a: 0_f32,
|
||||
b: 1_u16,
|
||||
};
|
||||
let _all = all.replace_a(77u8);
|
||||
let _all = all.replace_a(|_| 77u8);
|
||||
}
|
||||
|
||||
@@ -10,5 +10,5 @@ error[E0599]: no method named `replace_a` found for struct `AllSubsystems` in th
|
||||
6 | struct AllSubsystems {
|
||||
| -------------------- method `replace_a` not found for this
|
||||
...
|
||||
16 | let _all = all.replace_a(77u8);
|
||||
16 | let _all = all.replace_a(|_| 77u8);
|
||||
| ^^^^^^^^^ method not found in `AllSubsystems`
|
||||
|
||||
@@ -10,5 +10,5 @@ error[E0599]: no method named `replace_a` found for struct `AllSubsystems<u16>`
|
||||
6 | struct AllSubsystems<X> {
|
||||
| ----------------------- method `replace_a` not found for this
|
||||
...
|
||||
16 | let _all = all.replace_a(77u8);
|
||||
16 | let _all = all.replace_a(|_| 77u8);
|
||||
| ^^^^^^^^^ method not found in `AllSubsystems<u16>`
|
||||
|
||||
@@ -13,5 +13,5 @@ fn main() {
|
||||
a: 0u8,
|
||||
b: 1u16,
|
||||
};
|
||||
let _all: AllSubsystems<_,_> = all.replace_a::<u32>(777_777u32);
|
||||
let _all: AllSubsystems<_,_> = all.replace_a::<u32,_>(|_| 777_777u32);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user