| // --- original code --- | |
| cpp_inst! { SomeTrait for (T,U,V) in (i32,u32,u64), (i32,String,bool), ... { | |
| fn function1<A,B,C>(...) | |
| where (A,B,C): SomeTrait<T=A,U=B,V=C> { | |
| ... | |
| cpp!( (...) { ... }; // callsite 1 | |
| ... | |
| cpp!( (...) { ... }; // callsite 2 | |
| ... | |
| } | |
| fn function2<X,Y>(...) | |
| where (X,Y,u64): SomeTrait<T=A,U=B,V=u64> { | |
| ... | |
| cpp!( (...) { ... }; // callsite 3 | |
| ... | |
| } | |
| }} | |
| // --- after macro expansion --- | |
| trait SomeTrait { | |
| type T; | |
| type U; | |
| type V; | |
| fn cpp_callsite1(x:Self::T, y:Self::U) -> Self::V; | |
| fn cpp_callsite2(x:Self::U) -> Self::T; | |
| fn cpp_callsite3() -> Self::V; | |
| // and so on ... | |
| } | |
| // impl for combo 1 | |
| impl Sometrait for (i32,u32,u64) { | |
| type T = i32; | |
| type U = u32; | |
| type V = u64; | |
| fn cpp_callsite1(x:i32, y:u32) -> u64 { ffi_callsite1_combo1(x,y) } | |
| fn cpp_callsite2(x:u32) -> i32 { ffi_callsite2_combo1(x) } | |
| fn cpp_callsite3() -> u64 { ffi_callsite3_combo1() } | |
| } | |
| extern { | |
| fn ffi_callsite1_combo1(x:i32, y:u32) -> u64; | |
| fn ffi_callsite2_combo1(x:u32) -> i32; | |
| fn ffi_callsite3_combo1() -> u64; | |
| } | |
| // impl for combo 2 | |
| impl Sometrait for (i32,String,bool) { | |
| ... | |
| } | |
| extern { | |
| fn ffi_callsite1_combo2(x:i32, y:String) -> bool; | |
| fn ffi_callsite2_combo2(x:String) -> i32; | |
| fn ffi_callsite3_combo2() -> bool; | |
| } | |
| // impls for all other type combinations | |
| ... | |
| fn function1<A,B,C>(...) | |
| where (A,B,C): SomeTrait<T=A,U=B,V=C> { | |
| ... | |
| <(A,B,C) as Sometrait>::cpp_callsite1(...); | |
| ... | |
| <(A,B,C) as Sometrait>::cpp_callsite2(...); | |
| ... | |
| } | |
| fn function2<X,Y>(...) | |
| where (X,Y,u64): SomeTrait<T=X,U=Y,V=u64> { | |
| ... | |
| <(X,Y,u64) as Sometrait>::cpp_callsite3(...); | |
| ... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment