Keywords
The following list contains keywords that are reserved for current or future use by the Sway language. As such, they cannot be used as identifiers. Identifiers are names of functions, variables, parameters, modules, constants, attributes, types or traits, etc.
Keywords Currently in Use
The following is a list of keywords currently in use, with their functionality described.
as
- rename items inuse
statements, e.g.,use type::a as alias_name
abi
- defines a smart contract ABI in a syntactically similar way to traitsbreak
- exit a loop immediatelyconst
- define constant itemscontinue
- continue to the next loop iterationelse
- used in conjunction withif
conditions for control flow constructsenum
- define an enumerationfalse
- Boolean false literalfn
- define a function or the function pointer typeif
- branch based on the result of a conditional expressionimpl
- implement inherent or trait functionalitylet
- bind a variablematch
- exhaustively match a value to patternsmod
- define a modulemut
- denote mutability in references, or pattern bindingspub
- denote public visibility of Sway data structures, traits, or modulesref
- bind by referencereturn
- return early from a functionSelf
- a type alias for the type we are defining or implementingself
- method subjectstruct
- define a structuretrait
- define a traittrue
- Boolean true literaltype
- define a type alias or associated typeuse
- bring symbols into scopewhere
- specifies traits for generic typeswhile
- loop conditionally based on the result of an expression
Keywords Reserved for Possible Future Use
abstract
async
await
become
box
do
dyn
extern
for
in
loop
macro
move
override
priv
static
super
try
typeof
unsafe
unsized
virtual
yield
Special Keywords
Program Keywords
Keywords associated with defining the type of Sway program to compile
contract
- analogous to a deployed API with some database statelibrary
- Sway code that defines new common behaviorpredicate
- programs that return a Boolean value and which represent ownership of some resource upon execution to truescript
- a runnable bytecode on the chain, which executes once to perform a task
Attribute Keywords
Keywords associated with defining the functionality of attributes
allow
- overrides checks that would otherwise result in errors or warningsdoc
- specifies documentationinline
- suggests that a copy of the attributed function should be placed in the caller, rather than generating code to call the function where it is definedpayable
- implies method is payable for compile timestorage
- declaration that contains a list of stored variablestest
- marks a function to be executed as a testdeprecated
- marks an item as deprecated