Guest User

Untitled

a guest
Jul 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. // This doesn't work:
  2. //#[derive(Clone, Copy)]
  3. struct Copyable<'a, N: 'static> {
  4. #[allow(dead_code)]
  5. field: &'a N,
  6. }
  7.  
  8. // Resort to manual implementation:
  9. impl<'a, N> Clone for Copyable<'a, N> {
  10. fn clone(&self) -> Self {
  11. *self
  12. }
  13. }
  14.  
  15. impl<'a, N> Copy for Copyable<'a, N> {
  16. }
  17.  
  18. struct NonCopy;
  19.  
  20. fn main() {
  21. let thing = NonCopy;
  22.  
  23. let copyable = Copyable {
  24. field: &thing,
  25. };
  26.  
  27. drop(copyable);
  28. drop(copyable);
  29. }
Add Comment
Please, Sign In to add comment