You can also implement structs , which means you can attach functions to instances of structs
(Very similar to classes in TS)
struct Rect {
width: u32,
height: u32,
}
impl Rect {
fn area(&self) -> u32 {
self.width * self.height
}
}
fn main() {
let rect = Rect {
width: 30,
height: 50,
};
print!("The area of the rectangle is {}", rect.area());
}
struct Rect {
width: u32,
height: u32,
}
impl Rect {
fn print_str() {
println!("Inside the rect struct");
}
}
fn main() {
Rect::print_str();
}