Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #![allow(unused)]
  2.  
  3. trait UniType {}
  4. impl UniType for i32{}
  5. impl UniType for f32{}
  6. impl UniType for char{}
  7. impl UniType for String{}
  8.  
  9. struct UniVec {
  10. val: Vec<Box<dyn UniType>>
  11. }
  12.  
  13. impl UniVec {
  14. fn new() -> UniVec {
  15. UniVec {
  16. val: Vec::<Box<dyn UniType>>::new()
  17. }
  18. }
  19. fn push(&mut self, t: Box<dyn UniType>) {
  20. self.val.push(t);
  21. }
  22. }
  23.  
  24. fn main() {
  25. let mut uv = UniVec::new();
  26. uv.push(Box::new(100_i32));
  27. uv.push(Box::new(100_f32));
  28. uv.push(Box::new('A'));
  29. uv.push(Box::new("Praise the borrow checker =/\\=".to_string()));
  30.  
  31. // uncomment this line
  32. // uv.push(Box::new("Store is not implemented for &str yet, so this will break"));
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement