Structs

Syntax
Struct :
   struct IDENTIFIER {
   StructField*
   }

StructField :
   pub? IDENTIFIER : Type

A struct is a nominal struct type defined with the keyword struct.

An example of a struct item and its use:

struct Point {
    pub x: u256
    pub y: u256
}

fn pointy_stuff() {
    let p: Point = Point(x: 10, y: 11)
    let px: u256 = p.x
}

Builtin functions:

  • abi_encode() encodes the struct as an ABI tuple and returns the encoded data as a fixed-size byte array that is equal in size to the encoding.