How can you define and use a struct in Rust?

In Rust, a struct is a custom data type that allows you to group related data together. You can define a struct by using the struct keyword, followed by the name of the struct and a set of field names and their types, enclosed in curly braces. For example:
struct Point { x: i32, y: i32, }

This defines a struct called Point with two fields, x and y, both of which are of type i32.

You can create an instance of a struct using the new keyword or by directly initializing the fields.

let point = Point { x: 0, y: 0 }; let point = Point::new(0,0);

You can access the fields of a struct instance using the dot notation. For example:
let x = point.x;
You can also use the let keyword to destructure a struct instance into its fields.
let Point { x, y } = point;
You can also define methods for structs, which are functions that operate on instances of the struct. These methods are defined within the struct's definition and have access to the struct's fields. For example:
struct Point { x: i32, y: i32, } impl Point { fn distance_from_origin(&self) -> f64 { ((self.x.pow(2) + self.y.pow(2)) as f64).sqrt() } }

This defines a method distance_from_origin for the Point struct that calculates the distance of the point from the origin (0, 0).