Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #![allow(unused)]#![warn(unused_must_use)]
  2.  
  3. /// Types which implement this can be deserialized in-place from &'bytes mut [u8]
  4. ///
  5. ///
  6. pub
  7. trait InPlaceDeserialize {}
  8. impl InPlaceDeserialize for str {}
  9.  
  10. pub
  11. fn deserialize<'bytes, T : ?Sized + 'bytes> (
  12. bytes: &'bytes mut [u8],
  13. ) -> &'bytes T
  14. where
  15. T : InPlaceDeserialize
  16. {
  17. unimplemented!()
  18. }
  19.  
  20. pub
  21. fn client<'bytes, T> (
  22. bytes: &'bytes mut [u8],
  23. ) -> &'bytes mut [u8]
  24. where
  25. T : InPlaceDeserialize,
  26. {
  27. deserialize::<T>(bytes); // borrowed for an ephemeral lifetime
  28. bytes
  29. }
  30.  
  31. fn main ()
  32. {
  33. let mut s: &'static str = "static";
  34. let mut bytes = [];
  35. let short_s = deserialize::<str>(&mut bytes);
  36. s = short_s;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement