mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Add 'Static' type and improve type substitution codegen to accept it (#886)
* Add Static type which defers to Encode/Decode and impls EncodeAsType/DecodeAsType * rename to static_type and impl Deref/Mut * Improve type substitution in codegen so that concrete types can be swapped in * A couple of comment tweaks and no need for a macro export * Extend type substitution logic to work recursively on destination type * cargo fmt * Fix a couple of comments * update ui test outpuot * Add docs and missing_docs lint * Add test for replacing multiple of Ident * Update codegen/src/error.rs Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com> * update copyright year and fix ui test * simplify another error --------- Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
This commit is contained in:
+12
-14
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019-2022 Parity Technologies (UK) Ltd.
|
||||
// Copyright 2019-2023 Parity Technologies (UK) Ltd.
|
||||
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
|
||||
// see LICENSE for license details.
|
||||
|
||||
@@ -115,9 +115,9 @@ use std::str::FromStr;
|
||||
|
||||
use darling::FromMeta;
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro_error::{abort, abort_call_site, proc_macro_error};
|
||||
use subxt_codegen::{utils::Uri, DerivesRegistry, TypeSubstitutes};
|
||||
use syn::{parse_macro_input, punctuated::Punctuated, spanned::Spanned as _};
|
||||
use proc_macro_error::{abort_call_site, proc_macro_error};
|
||||
use subxt_codegen::{utils::Uri, CodegenError, DerivesRegistry, TypeSubstitutes};
|
||||
use syn::{parse_macro_input, punctuated::Punctuated};
|
||||
|
||||
#[derive(Debug, FromMeta)]
|
||||
struct RuntimeMetadataArgs {
|
||||
@@ -181,16 +181,14 @@ pub fn subxt(args: TokenStream, input: TokenStream) -> TokenStream {
|
||||
}
|
||||
|
||||
let mut type_substitutes = TypeSubstitutes::new(&crate_path);
|
||||
if let Err(err) = type_substitutes.extend(args.substitute_type.into_iter().map(
|
||||
|SubstituteType { ty, with }| {
|
||||
(
|
||||
ty,
|
||||
with.try_into()
|
||||
.unwrap_or_else(|(node, msg): (syn::Path, String)| abort!(node.span(), msg)),
|
||||
)
|
||||
},
|
||||
)) {
|
||||
return err.into_compile_error().into();
|
||||
let substitute_args_res: Result<(), _> = args.substitute_type.into_iter().try_for_each(|sub| {
|
||||
sub.with
|
||||
.try_into()
|
||||
.and_then(|with| type_substitutes.insert(sub.ty, with))
|
||||
});
|
||||
|
||||
if let Err(err) = substitute_args_res {
|
||||
return CodegenError::from(err).into_compile_error().into();
|
||||
}
|
||||
|
||||
let should_gen_docs = args.generate_docs.is_present();
|
||||
|
||||
Reference in New Issue
Block a user