ABSTRACT

This chapter discusses the definition of struct and its installation with its relevant examples and syntax. Structs can store references to data that belongs to someone else, but doing so requires the usage of lifetimes. Lifetimes guarantee that data referenced by a struct is valid for the same amount of time as the struct itself. Methods are declared in the same way functions are: with the functions keyword and their name. They may have parameters as well as a return value. They include code that is executed when they are called from another location. The area function accesses the width and height fields of the rectangle instance. Calculate the area of the rectangle using its width and height fields, as stated in function signature for the area.