⌘K

Icon SunFilledIcon MoonStars

Icon LinkKeywords

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.

Icon LinkKeywords Currently in Use

The following is a list of keywords currently in use, with their functionality described.

  • as - rename items in use statements, e.g., use type::a as alias_name
  • abi - defines a smart contract ABI in a syntactically similar way to traits
  • break - exit a loop immediately
  • const - define constant items
  • continue - continue to the next loop iteration
  • else - used in conjunction with if conditions for control flow constructs
  • enum - define an enumeration
  • false - Boolean false literal
  • fn - define a function or the function pointer type
  • if - branch based on the result of a conditional expression
  • impl - implement inherent or trait functionality
  • let - bind a variable
  • match - exhaustively match a value to patterns
  • mod - define a module
  • mut - denote mutability in references, or pattern bindings
  • pub - denote public visibility of Sway data structures, traits, or modules
  • ref - bind by reference
  • return - return early from a function
  • Self - a type alias for the type we are defining or implementing
  • self - method subject
  • struct - define a structure
  • trait - define a trait
  • true - Boolean true literal
  • type - define a type alias or associated type
  • use - bring symbols into scope
  • where - specifies traits for generic types
  • while - loop conditionally based on the result of an expression

Icon LinkKeywords 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

Icon LinkSpecial Keywords

Icon LinkProgram Keywords

Keywords associated with defining the type of Sway program to compile

  • contract - analogous to a deployed API with some database state
  • library - Sway code that defines new common behavior
  • predicate - programs that return a Boolean value and which represent ownership of some resource upon execution to true
  • script - a runnable bytecode on the chain, which executes once to preform a task

Icon LinkAttribute Keywords

Keywords associated with defining the functionality of attributes

  • allow - overrides checks that would otherwise result in errors or warnings
  • doc - specifies documentation
  • inline - 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 defined
  • payable - implies method is payable for compile time
  • storage - declaration that contains a list of stored variables
  • test - marks a function to be executed as a test
  • deprecated - marks an item as deprecated