Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait Collection<T>: Sized {
- fn take_items(self) -> Vec<T>;
- }
- struct AList<T> {
- items: Vec<T>,
- }
- impl<T> AList<T> {
- pub fn new() -> Self {
- Self { items: Vec::new() }
- }
- }
- impl<T> Collection<T> for AList<T> {
- fn take_items(self) -> Vec<T> {
- self.items
- }
- }
- struct BList<T> {
- items: Vec<T>,
- }
- impl<T> Collection<T> for BList<T> {
- fn take_items(self) -> Vec<T> {
- self.items
- }
- }
- fn map_a_to_b(coll: Box<Collection<i64>>) -> Box<Collection<i64>> {
- Box::new(BList {
- items: coll.take_items(),
- })
- }
- fn main() {
- let mut coll: Box<Collection<i64>> = Box::new(AList::new());
- coll = map_a_to_b(coll);
- }
Add Comment
Please, Sign In to add comment