Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. trait Trait {
  2. fn bar(&self);
  3. }
  4.  
  5. struct A<T: Trait> {
  6. a: T,
  7. }
  8.  
  9. struct B<T: Trait> {
  10. b: Option<A<T>>,
  11. }
  12.  
  13. struct C;
  14.  
  15. impl C {
  16. fn new() -> Self {
  17. Self {}
  18. }
  19. }
  20.  
  21. impl Trait for C {
  22. fn bar(&self) {
  23.  
  24. }
  25. }
  26.  
  27. impl<T: Trait> A<T> {
  28. fn new(a: T) -> Self {
  29. Self {
  30. a
  31. }
  32. }
  33. }
  34.  
  35. impl<T: Trait> B<T> {
  36. fn new() -> Self {
  37. Self {
  38. b: None,
  39. }
  40. }
  41.  
  42. fn process(&mut self) {
  43. self.b = Some(A::new(C::new()));
  44. }
  45. }
  46.  
  47. fn main() {
  48. let b = B::new();
  49. b.process();
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement