aboutsummaryrefslogtreecommitdiff
path: root/src/trait_sig.rs
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-11-25 10:30:54 +0100
committerMartin Fischer <martin@push-f.com>2021-11-26 11:45:53 +0100
commit7489a3c2246e7ea2483446dd2ed3fdbfaf462c1a (patch)
treefc2670f56f7cc16567eb10d88f9439abb9098298 /src/trait_sig.rs
parent43950edc4f26a07055fb917fa8bbb262276e2a08 (diff)
introduce #[convert] attribute
Diffstat (limited to 'src/trait_sig.rs')
-rw-r--r--src/trait_sig.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/trait_sig.rs b/src/trait_sig.rs
index 5d8eddf..a1be44f 100644
--- a/src/trait_sig.rs
+++ b/src/trait_sig.rs
@@ -1,4 +1,5 @@
use std::collections::HashMap;
+use std::rc::Rc;
use proc_macro2::Span;
use syn::{
@@ -8,6 +9,7 @@ use syn::{Ident, Signature, TypeImplTrait};
use crate::match_assoc_type;
use crate::parse_assoc_type::BoxType;
+use crate::parse_attrs::Convert;
use crate::syn_utils::{iter_type, trait_bounds};
use crate::transform::{dynamize_function_bounds, TransformError, TypeConverter};
@@ -21,6 +23,7 @@ pub enum TypeTransform {
IntoIterMapCollect(Vec<TypeTransform>),
Iterator(BoxType, Box<TypeTransform>),
Result(Box<TypeTransform>, Box<TypeTransform>),
+ Verbatim(Rc<Convert>),
}
#[derive(Debug)]
@@ -83,6 +86,7 @@ pub fn convert_trait_signature(
},
ReturnType::Default => TypeTransform::NoOp,
};
+
Ok(SignatureChanges {
return_type,
type_param_transforms,
@@ -151,11 +155,12 @@ mod tests {
transform::{TransformError, TypeConverter},
};
- fn test_converter() -> TypeConverter<'static> {
+ fn test_converter() -> TypeConverter {
TypeConverter {
assoc_type_conversions: HashMap::new(),
collections: HashMap::new(),
trait_ident: format_ident!("test"),
+ type_conversions: HashMap::new(),
}
}
@@ -185,7 +190,7 @@ mod tests {
let mut type_converter = test_converter();
let ident = format_ident!("A");
let dest_inner = Type::Verbatim(quote! {Example});
- let dest = DestType::Into(&dest_inner);
+ let dest = DestType::Into(dest_inner);
type_converter.assoc_type_conversions.insert(ident, dest);
assert!(matches!(