Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Box[T]{
- field buffer:[sizeof(T)] u8;
- method new(self:out Box[T], t:in T){
- unsafe{
- *self = Box[T]{
- buffer = uninitialized
- };
- *(self->buffer as out T) = *t;
- }
- }
- method borrow(self:ref Box[T]):ref T{
- unsafe{
- return (self->buffer as ref T);
- }
- }
- }
- function outer(){
- let b:Box[i32] = Box[i32]::new(&in 42);
- inner(b.borrow());
- }
- function inner(p:ref i32){
- //do whatever you want with p
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement