diff options
author | Martin Fischer <martin@push-f.com> | 2021-11-25 10:30:54 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-11-26 11:45:53 +0100 |
commit | 7489a3c2246e7ea2483446dd2ed3fdbfaf462c1a (patch) | |
tree | fc2670f56f7cc16567eb10d88f9439abb9098298 /src/lib.rs | |
parent | 43950edc4f26a07055fb917fa8bbb262276e2a08 (diff) |
introduce #[convert] attribute
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -93,9 +93,10 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream { } let mut type_converter = TypeConverter { - collections: method_attrs.collections, - assoc_type_conversions: HashMap::new(), trait_ident: original_trait.ident.clone(), + assoc_type_conversions: HashMap::new(), + collections: method_attrs.collections, + type_conversions: method_attrs.type_conversions, }; for item in &original_trait.items { @@ -122,9 +123,10 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream { let mut objectifiable_methods: Vec<(Signature, SignatureChanges)> = Vec::new(); - for item in &original_trait.items { + for item in &mut original_trait.items { if let TraitItem::Method(method) = item { let mut signature = method.sig.clone(); + match convert_trait_signature(&mut signature, &type_converter) { Ok(parsed_method) => objectifiable_methods.push((signature, parsed_method)), Err((span, err)) => match err { @@ -169,7 +171,7 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream { return abort!(span, "dynamize does not support qualified associated types") } MethodError::Transform(TransformError::SelfQualifiedAsOtherTrait) => { - return abort!(span, "dynamize does not support Self qualified as another trait") + return abort!(span, "dynamize does not know how to convert this type (you can tell it with #[convert])") } MethodError::UnconvertedAssocType => { return abort!(span, "dynamize does not support associated types here") @@ -471,6 +473,11 @@ impl TypeTransform { quote! {#arg.into_iter().map(|(#(#idents),*)| (#(#transforms),*)).collect()} } TypeTransform::NoOp => arg, + TypeTransform::Verbatim(convert) => { + let ident = &convert.ident; + let block = &convert.block; + quote! { {let #ident = #arg; #block }} + } } } } |