Ξενάγηση στη Rust Πίνακας Περιεχομένων

[Αμετάφραστο] Encapsulation With Methods

Rust supports the concept of an object that is a struct associated with some functions (also known as methods).

The first parameter of any method must be a reference to the instance associated with the method call (e.g. instanceOfObj.foo()). Rust uses:

Methods are defined within an implementation block with keyword impl:

impl MyStruct { 
    ...
    fn foo(&self) {
        ...
    }
}