Guest User

Untitled

a guest
Jan 18th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. mod final_impl {
  2. #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
  3. #[repr(transparent)]
  4. pub struct Final<T>(T);
  5.  
  6. impl<T> Final<T> {
  7. pub fn new(val: T) -> Self {
  8. Self(val)
  9. }
  10. }
  11.  
  12. impl<T> std::ops::Deref for Final<T> {
  13. type Target = T;
  14. fn deref(&self) -> &T {
  15. &self.0
  16. }
  17. }
  18. }
  19.  
  20. use final_impl::Final;
  21.  
  22. struct MyStruct {
  23. vec: Final<Vec<u8>>,
  24. }
  25.  
  26. impl MyStruct {
  27. fn new() -> Self {
  28. Self {
  29. vec: Final::new(vec![0, 1, 2, 3]),
  30. }
  31. }
  32. }
  33.  
  34. fn main() {
  35. let mut s = MyStruct::new();
  36. s.vec.push(4);
  37. }
Add Comment
Please, Sign In to add comment