Mojo trait
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^)movingImplemented 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
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!