Movable
The Movable trait denotes a type whose value can be moved.
Implement the Movable trait on Foo which requires the
def __init__(out self, *, deinit take: Self) method:
struct Foo(Movable):
def __init__(out self):
pass
def __init__(out self, *, deinit take: Self):
print("moving")
You can now use the ^ suffix to transfer owned values instead of copying:
def return_foo[T: Movable](var foo: T) -> T:
return foo^
var foo = Foo()
var res = return_foo(foo^)
moving
Implemented traits
Required methods
__init__
__init__(out self: _Self, *, deinit take: _Self)
Create a new instance of the value by moving the value of another.
Args:
- take (
_Self): The value to move.
Returns:
_Self