Rust doesn't have classes like other object-oriented languages. The impl
(implementation) keyword in Rust acts kind of like the class
keyword would.
Functions can be defined inside implementations (example taken from docs.rust-lang.org):
impl Example {
fn boo() {
println!("boo! Example::boo() was called!");
}
}
Functions inside implementations can be called with ::
or .
syntax.
In JavaScript, we tend to think of methods as exiting on classes. In Rust, methods can exist in a variety of places, including in implementations, in structs, and in enums.
Traits are kind of like interfaces in other languages. Similar to those other langugaes, an implementation can inherit its properties from traits.