Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. use std::env::args;
  2. use std::any::Any;
  3.  
  4. #[macro_use]
  5. extern crate t_bang;
  6. use t_bang::*;
  7.  
  8. pub enum DValue {
  9. Null,
  10. Boolean(bool),
  11. Int(i32),
  12. Long(i64),
  13. Float(f32),
  14. Double(f64),
  15. Bytes(Vec<u8>),
  16. Str(String),
  17. }
  18.  
  19. fn main() {
  20. use DValue::*;
  21.  
  22. let vector = vec![Boolean(true), Int(21), Float(3.0)];
  23.  
  24. let mut bag_of_any: Vec<Box<dyn Any>> = vec![];
  25.  
  26. // vector.iter().enumerate().for_each(|(index, item)| {
  27. // | ^^^^^^ borrowed value does not live long enough
  28.  
  29. vector.iter().enumerate().for_each(|(index, item)| {
  30. match item {
  31. Boolean(val) => bag_of_any[index] = Box::new(val),
  32. Int(val) => bag_of_any[index] = Box::new(val),
  33. Long(val) => bag_of_any[index] = Box::new(val),
  34. Float(val) => bag_of_any[index] = Box::new(val),
  35. Double(val) => bag_of_any[index] = Box::new(val),
  36. Bytes(val) => bag_of_any[index] = Box::new(val),
  37. Str(val) => bag_of_any[index] = Box::new(val),
  38. Null => bag_of_any[index] = Box::new("null"),
  39. }
  40. });
  41.  
  42. for item in bag_of_any.iter() {
  43. println!("{:?}", item);
  44. println!("{:?}", t!(item));
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement