Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::env::args;
- use std::any::Any;
- #[macro_use]
- extern crate t_bang;
- use t_bang::*;
- pub enum DValue {
- Null,
- Boolean(bool),
- Int(i32),
- Long(i64),
- Float(f32),
- Double(f64),
- Bytes(Vec<u8>),
- Str(String),
- }
- fn main() {
- use DValue::*;
- let vector = vec![Boolean(true), Int(21), Float(3.0)];
- let mut bag_of_any: Vec<Box<dyn Any>> = vec![];
- // vector.iter().enumerate().for_each(|(index, item)| {
- // | ^^^^^^ borrowed value does not live long enough
- vector.iter().enumerate().for_each(|(index, item)| {
- match item {
- Boolean(val) => bag_of_any[index] = Box::new(val),
- Int(val) => bag_of_any[index] = Box::new(val),
- Long(val) => bag_of_any[index] = Box::new(val),
- Float(val) => bag_of_any[index] = Box::new(val),
- Double(val) => bag_of_any[index] = Box::new(val),
- Bytes(val) => bag_of_any[index] = Box::new(val),
- Str(val) => bag_of_any[index] = Box::new(val),
- Null => bag_of_any[index] = Box::new("null"),
- }
- });
- for item in bag_of_any.iter() {
- println!("{:?}", item);
- println!("{:?}", t!(item));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement