I should have been more clear. I meant
- the implementation of
'a T
would be a pointer - the syntax for its usage would be the same as used for non-reference types
// allocated in the scope associates with 'a
// possibly in a parent stack frame
// if indeed allocated in a parent stack frame
// our frame will contain a pointer to it
let 'a a = A{ a : 8u };
"Owning reference" &own 'a T
would mean:
- memory occupied by the value is borrowed and may possibly not outlive the lifetime of the reference
- you still own the content of that memory
- the pointer that you have in your hands is the only valid pointer to that memory
- you can write to it
- you can move out of it
- assigning to another
&own a' T
is a move - if
&own a' T
is destroyed (was assigned to local variable in a scope and not moved out of it by end of the scope) thendrop
is executed
As pointed out by @dhm owning references can generally be implemented in user code now.
Above 'a
was part of let
binding. Could it instead be part of the type?
// struct allocated in a parent frame if 'a is fn's param
// the pointer to the newly allocated struct resides in current stack frame
// implementation of a is &own 'a A
// syntax for a is that of A
let a = 'a A{ a : 8u };
// pair allocated in the current stack frame
// 2nd element of the pair is a pointer
// that pointer points to a struct allocated in the stack frame associated with 'a
let pair = ( 8u, 'a A{ a : 8u } );
Having written this all I started thinking about Deref
coercions