Guest User

Untitled

a guest
Mar 23rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. trait Collection<T>: Sized {
  2. fn take_items(self) -> Vec<T>;
  3. }
  4.  
  5. struct AList<T> {
  6. items: Vec<T>,
  7. }
  8.  
  9. impl<T> AList<T> {
  10. pub fn new() -> Self {
  11. Self { items: Vec::new() }
  12. }
  13. }
  14.  
  15. impl<T> Collection<T> for AList<T> {
  16. fn take_items(self) -> Vec<T> {
  17. self.items
  18. }
  19. }
  20.  
  21. struct BList<T> {
  22. items: Vec<T>,
  23. }
  24.  
  25. impl<T> Collection<T> for BList<T> {
  26. fn take_items(self) -> Vec<T> {
  27. self.items
  28. }
  29. }
  30.  
  31. fn map_a_to_b(coll: Box<Collection<i64>>) -> Box<Collection<i64>> {
  32. Box::new(BList {
  33. items: coll.take_items(),
  34. })
  35. }
  36.  
  37. fn main() {
  38. let mut coll: Box<Collection<i64>> = Box::new(AList::new());
  39. coll = map_a_to_b(coll);
  40. }
Add Comment
Please, Sign In to add comment