Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. use std::borrow::Cow;
  2.  
  3. struct Foo<'a>(Cow<'a, [u8]>);
  4. struct FooList<'a>(Vec<Foo<'a>>);
  5.  
  6. impl<'a> std::borrow::ToOwned for Foo<'a> {
  7. type Owned = Foo<'static>;
  8.  
  9. fn to_owned(&self) -> Foo<'static> {
  10. Foo(self.0.to_vec().into())
  11. }
  12. }
  13.  
  14.  
  15. impl<'a> Clone for FooList<'a> {
  16. fn clone(&self) -> FooList<'static> {
  17. FooList(self.0.iter().map(|foo| {
  18. let vec = foo.0.clone().into_owned();
  19. Foo(vec.into())
  20. }).collect())
  21. }
  22. }
  23.  
  24. fn main() {
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement