Skip to content

Function

Liu Jun edited this page Dec 9, 2019 · 3 revisions

Function is similar to C++ but more powerful.

// implemented
fn func() -> (i32, i32)
{
    // ...
    return a, b;
}

// unimplemented
var i1, _ = func();

You can return multiple values and use _ to ignore the one you don't want.

// unimplemented
fn func() -> i32&
{
    i32 tmp = 56;
    return ref(tmp);
}

fn proto() -> (i32, Class&);

If you want to do type cast, you can do it where it will return or declare it at the function header.

Clone this wiki locally