You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
importspace.Spaceship;spaceship1mut=space.Spaceship{name: "Apollo"};spaceship1.rename("Saturn V");rename(&spaceship1"Saturn V");// error (not in scope)
You can use UFCS for anything, it just needs to be in scope
importspace.Spaceship.renameaschange_namechange_name(spaceship1,"Soyuz");spaceship1.change_name("Soyuz");rename(spaceship1,"Soyuz");// error (not in scope)
Wildcard imports bring every direct child into scope:
importspace.*;spaceship=Spaceship{name: "Apollo"};spaceship.rename("Starship");rename("Starship");// error (not in scope)
Variable declaration
mut is specified alongside the type, and it's consistent between both variable and struct field declarations
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)
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
The text was updated successfully, but these errors were encountered: