SHARE
TWEET

Untitled

a guest May 27th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::ops::Deref;
  2.  
  3. trait ToBoxed {
  4.     type Owned: ?Sized;
  5.    
  6.     fn to_boxed(&self) -> Box<Self::Owned>;
  7. }
  8.  
  9. impl<T: Clone> ToBoxed for [T] {
  10.     type Owned = Self;
  11.    
  12.     fn to_boxed(&self) -> Box<Self::Owned> {
  13.        self.to_vec().into_boxed_slice()
  14.     }
  15. }
  16.  
  17. impl ToBoxed for str {
  18.     type Owned = Self;
  19.    
  20.     fn to_boxed(&self) -> Box<Self::Owned> {
  21.        self.to_string().into_boxed_str()
  22.     }
  23. }
  24.  
  25. impl<P> ToBoxed for P
  26. where P: Deref, P::Target: ToBoxed {
  27.     type Owned = <P::Target as ToBoxed>::Owned;
  28.    
  29.     fn to_boxed(&self) -> Box<Self::Owned> {
  30.        <P::Target>::to_boxed(self)
  31.     }
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top