Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

A struct is a user-defined data type.

It is a product type - a data type made by combining multiple fields together into a single type.

Example: a 'Rectangle' struct

edit edit source

As structs store multiple different fields in a single collection, we can make a Rectangle struct like this (written in Rust for this example):

struct Rectangle {
    width: u32,
    height: u32,
    color: Color,
}

And our Color struct could look like this, another product type:

struct Color {
    red: u8,
    green: u8,
    blue: u8,
    alpha: u8,
}

Other algebraic data types

edit edit source

Please see: Algebraic data type