SHARE
TWEET

Untitled

a guest Jan 18th, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
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