Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #![allow(dead_code)]
  2.  
  3. use std::marker::PhantomData;
  4.  
  5. trait Abc {}
  6.  
  7. struct ImplAbc;
  8. impl Abc for ImplAbc {}
  9.  
  10. struct WrappingAbc<'a, A: Abc> {
  11. value: &'a A,
  12. }
  13. impl<'a, A: Abc> Abc for WrappingAbc<'a, A> {}
  14. impl<'a, A: Abc> WrappingAbc<'a, A> {
  15. fn new(value: &'a A) -> Self {
  16. WrappingAbc { value, }
  17. }
  18. }
  19.  
  20. struct AnotherWrapper<'a, K: Kind, A: Abc, S> {
  21. value: &'a A,
  22. other: usize,
  23. phantom_data: PhantomData<(K, S)>,
  24. }
  25. impl<'a, K: Kind, A: Abc, S: Strategy<K, A>> AnotherWrapper<'a, K, A, S> {
  26. fn new(value: &'a A) -> Self {
  27. AnotherWrapper {
  28. value,
  29. other: 0,
  30. phantom_data: PhantomData,
  31. }
  32. }
  33. }
  34. impl<'a, 'b, A: Abc, S: Strategy<KindTwo, A>> AnotherWrapper<'a, KindTwo, WrappingAbc<'b, A>, S> {
  35. fn replace_value(
  36. old: AnotherWrapper<KindOne, A, S>,
  37. newvalue: &'a WrappingAbc<'b, A>,
  38. ) -> Self {
  39. AnotherWrapper {
  40. value: newvalue,
  41. other: old.other,
  42. phantom_data: PhantomData,
  43. }
  44. }
  45. }
  46. trait Kind {}
  47. struct KindOne;
  48. impl Kind for KindOne {}
  49. struct KindTwo;
  50. impl Kind for KindTwo {}
  51.  
  52.  
  53. trait Strategy<K: Kind, A: Abc>: Sized {}
  54. struct StrategyImpl;
  55. impl<K: Kind, A: Abc> Strategy<K, A> for StrategyImpl {}
  56.  
  57. fn f<'a, A: Abc>(x: &'a A) {
  58. let first = AnotherWrapper::<KindOne, A, StrategyImpl>::new(x);
  59. let wrapper = WrappingAbc::new(x);
  60. let second = AnotherWrapper::replace_value(first, &wrapper);
  61. move_away(second);
  62. }
  63.  
  64. fn move_away<'a, A: Abc, S: Strategy<KindTwo, A>>(_argument: AnotherWrapper<'a, KindTwo, A, S>) {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement