Composite Types
Structs
Structs in Frost provide a way to create custom data types by combining different fields into a single unit. They serve as the foundation for building complex data structures.
Basic Structure Definition
point :: struct {
x -> double
y -> double
}
color :: struct {
r -> byte
g -> byte
b -> byte
a -> byte
}Creating and Using Structs
% Creating instances
origin: point = point {
x -> 0,0
y -> 0,0
}
% Accessing fields
x_coord: double = origin.xNested Structures
Remember that structs in Frost are designed to be efficient and safe, with zero-cost abstractions where possible. The compiler optimizes struct layouts and ensures memory safety while maintaining high performance.
Last updated