struct Spaceship {
name: str;
fn rename(spaceship &Spaceship, name str) {
set spaceship.name = name;
}
}
If you only import Spaceship, rename is not in scope. That means you cannot use rename() as an independent function, but you can use the rename method.
mut is specified alongside the type, and it's consistent between both variable and struct field declarations
// variables
x = value;
x mut = value;
set x = value;
// struct fields
x type;
x mut type;
set str.x = value;
List declaration
Declarations for the 3 different types of lists.
Type arguments: <item_type, list_capacity>.
[1, 2, 3] is a special shorthand for List, but there are no other special shorthands you need to think about.
Explicit imports are much easier to read/navigate outside of a code editor, when there's no Go to definition (like on GitHub)
Officially discourage wildcard imports, but don't show warnings for them
Show warnings when there are wildcard imports if the code is publishable to a package registry (aka private: true isn't specified in package.json-equivalent)
Private-by-default struct fields
struct Spaceship {
pub fuel u64;
}
Multi-statement loop conditions
while {
ship = getShip(5);
ship.canFly()
} do {
ship.fly();
}
These are my personal suggestions syntax suggestions
Enum variant access & type guards
This shows a few things:
Err
, we can safely access theOk
value.I think this is very simple and easy to understand.
Potential equivalent shorthand:
Methods, and how they work with UFCS
Define methods:
If you only import
Spaceship
,rename
is not in scope. That means you cannot userename()
as an independent function, but you can use therename
method.You can use UFCS for anything, it just needs to be in scope
Wildcard imports bring every direct child into scope:
Variable declaration
mut
is specified alongside the type, and it's consistent between both variable and struct field declarationsList declaration
Declarations for the 3 different types of lists. Type arguments:
<item_type, list_capacity>
.[1, 2, 3]
is a special shorthand forList
, but there are no other special shorthands you need to think about.Discourage wildcard imports
Go to definition
(like on GitHub)private: true
isn't specified inpackage.json
-equivalent)Private-by-default struct fields
Multi-statement loop conditions
Shorter keywords
exported
->pub
import
->use