-
Notifications
You must be signed in to change notification settings - Fork 248
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
Retain specific runtime APIs #961
Retain specific runtime APIs #961
Conversation
cli/src/commands/metadata.rs
Outdated
match (opts.pallets.as_ref(), opts.runtime_apis.as_ref()) { | ||
(Some(pallets), Some(runtime_apis)) => retain_metadata( | ||
&mut metadata_v15, | ||
|pallet_name| pallets.iter().any(|p| &**p == pallet_name), | ||
|runtime_api_name| runtime_apis.iter().any(|p| &**p == runtime_api_name), | ||
), | ||
(Some(pallets), None) => retain_metadata( | ||
&mut metadata_v15, | ||
|pallet_name| pallets.iter().any(|p| &**p == pallet_name), | ||
|_| true, | ||
), | ||
(None, Some(runtime_apis)) => retain_metadata( | ||
&mut metadata_v15, | ||
|_| true, | ||
|runtime_api_name| runtime_apis.iter().any(|p| &**p == runtime_api_name), | ||
), | ||
(None, None) => {} | ||
} | ||
metadata = metadata_v15.into(); |
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.
The way to avoid the repetition would be by boxing the closures like so:
let retain_pallets_fn: Box<dyn Fn(&str) -> bool> = match opts.pallets.as_ref() {
Some(pallets) => Box::new(|name| pallets.iter().any(|p| &**p == name)),
None => Box::new(|_| true)
};
let retain_runtime_apis_fn: Box<dyn Fn(&str) -> bool> = match opts.runtime_apis.as_ref() {
Some(apis) => Box::new(|name| apis.iter().any(|p| &**p == name)),
None => Box::new(|_| true)
};
retain_metadata(&mut metadata_v15, retain_pallets_fn, retain_runtime_apis_fn);
metadata = metadata_v15.into();
A little extra overhead but not a big deal :)
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.
Ah, nice, yeah that is definitely a solution. I still want to keep a check that at least one of the arguments is set, because if not we can avoid calling the retain_metadata
function alltogether.
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.
Yeah I wouldn't reaplce the initial check, just the highlighted lines :)
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.
Nice work!
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.
Amazing PR! 👍
fixes #933
I integrated the retaining of specific runtime APIs into the existing
retain_metadata_pallets
functionality, because it is more efficient to join the two operations in one place. As for the typing: I tried usindOption<FnMut(&str) -> bool>
as a sensiple argument type for bothpallets_filter
andruntime_apis_filter
but spent way too much time on lifetime issues and could not get it going well. So now I settled for just passing|_| true
closures, when all elements should be retained. Not so nice, I know, but should work.