Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. trait Base {
  2. type Item;
  3. type Item2;
  4. }
  5.  
  6. trait Service {
  7. type R;
  8. type E;
  9. type C: Base<Item = Self::R, Item2 = Self::E>;
  10. }
  11.  
  12. fn create() -> impl Service {
  13. struct BaseImpl {}
  14. impl Base for BaseImpl {
  15. type Item = u64;
  16. type Item2 = String;
  17. }
  18.  
  19. struct ServiceImpl {}
  20. impl Service for ServiceImpl {
  21. type R = u64;
  22. type E = String;
  23. type C = BaseImpl;
  24. }
  25.  
  26. ServiceImpl {}
  27. }
  28.  
  29. fn create_config() -> impl Service {
  30. let mut srv = create();
  31. srv
  32. }
  33.  
  34. struct S1<T: Service> {
  35. service: T,
  36. }
  37.  
  38. impl<S: Service> S1<S> {
  39. fn new() -> Self {
  40. S1{
  41. service: create_config()
  42. }
  43. }
  44. }
  45.  
  46. struct S2<T: Service> {
  47. s1: S1<T>,
  48. }
  49.  
  50. fn create_s2<S: Service>(s1: S1<S>) -> S2<S>{
  51. S2{s1}
  52. }
  53.  
  54. fn main() {
  55. let s1 = S1::new();
  56. let s2 = create_s2(s1);
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement