Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait Base {
- type Item;
- type Item2;
- }
- trait Service {
- type R;
- type E;
- type C: Base<Item = Self::R, Item2 = Self::E>;
- }
- fn create() -> impl Service {
- struct BaseImpl {}
- impl Base for BaseImpl {
- type Item = u64;
- type Item2 = String;
- }
- struct ServiceImpl {}
- impl Service for ServiceImpl {
- type R = u64;
- type E = String;
- type C = BaseImpl;
- }
- ServiceImpl {}
- }
- fn create_config() -> impl Service {
- let mut srv = create();
- srv
- }
- struct S1<T: Service> {
- service: T,
- }
- impl<S: Service> S1<S> {
- fn new() -> Self {
- S1{
- service: create_config()
- }
- }
- }
- struct S2<T: Service> {
- s1: S1<T>,
- }
- fn create_s2<S: Service>(s1: S1<S>) -> S2<S>{
- S2{s1}
- }
- fn main() {
- let s1 = S1::new();
- let s2 = create_s2(s1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement