structFooRc { bar: Rc<String>, } structFooArc { bar: Arc<String>, }
不過這當然沒什麼好說的
Macro solution
理論上辦得到,不過沒什麼優點
GAT Solution
我希望能寫成這樣
1
structFoo<P: Pointer> { bar: P<String>, }
這樣是編譯不會過的,有了GAT之後,可以寫成這樣
1 2 3 4 5 6 7
traitPointerFamily { typePointer<T>; } structRcFamily; // Just a marker type; could also use e.g. an empty enum structArcFamily; // Just a marker type; could also use e.g. an empty enum impl PointerFamily for RcFamily { typePointer<T> = Rc<T>; } impl PointerFamily for ArcFamily { typePointer<T> = Arc<T>; }
structFoo<P: PointerFamily> { bar: P::Pointer<String>, }