Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::cell::{Ref, RefCell};
- use std::rc::Rc;
- struct First {}
- struct Second {}
- enum TestEnum {
- First(First),
- Second(Second),
- }
- struct FirstWrapper<'a> {
- first: &'a First,
- }
- struct SecondWrapper<'a> {
- second: &'a Second,
- }
- trait Wrapper<'a> {}
- impl<'a> Wrapper<'a> for FirstWrapper<'a> {}
- impl<'a> Wrapper<'a> for SecondWrapper<'a> {}
- fn wrap<'a>(val: Ref<'a, TestEnum>) -> Box<Wrapper<'a>> {
- match &*val {
- &TestEnum::First(ref first) => Box::new(FirstWrapper { first }),
- &TestEnum::Second(ref second) => Box::new(SecondWrapper { second }),
- }
- }
- fn main() {
- let vec: Vec<Rc<RefCell<TestEnum>>> = vec![];
- let borrowed: Vec<Box<Wrapper>> = vec.iter().map(|i| i.borrow()).map(wrap).collect::<Vec<_>>();
- println!("{:?}", borrowed);
- }
Add Comment
Please, Sign In to add comment