Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![allow(unused)]
- trait UniType {}
- impl UniType for i32{}
- impl UniType for f32{}
- impl UniType for char{}
- impl UniType for String{}
- struct UniVec {
- val: Vec<Box<dyn UniType>>
- }
- impl UniVec {
- fn new() -> UniVec {
- UniVec {
- val: Vec::<Box<dyn UniType>>::new()
- }
- }
- fn push(&mut self, t: Box<dyn UniType>) {
- self.val.push(t);
- }
- }
- fn main() {
- let mut uv = UniVec::new();
- uv.push(Box::new(100_i32));
- uv.push(Box::new(100_f32));
- uv.push(Box::new('A'));
- uv.push(Box::new("Praise the borrow checker =/\\=".to_string()));
- // uncomment this line
- // uv.push(Box::new("Store is not implemented for &str yet, so this will break"));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement