Advertisement
tinyevil

Untitled

Jul 27th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. struct Box[T]{
  2. field buffer:[sizeof(T)] u8;
  3.  
  4. method new(self:out Box[T], t:in T){
  5. unsafe{
  6. *self = Box[T]{
  7. buffer = uninitialized
  8. };
  9. *(self->buffer as out T) = *t;
  10. }
  11. }
  12.  
  13. method borrow(self:ref Box[T]):ref T{
  14. unsafe{
  15. return (self->buffer as ref T);
  16. }
  17. }
  18. }
  19.  
  20. function outer(){
  21. let b:Box[i32] = Box[i32]::new(&in 42);
  22.  
  23. inner(b.borrow());
  24. }
  25.  
  26. function inner(p:ref i32){
  27. //do whatever you want with p
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement