impl blocks & methods (self)
Në shqip: Metodat në Rust
ShpjegimiSQ
Me impl i shton metoda një struct-i. Metodat marrin &self (lexojnë), &mut self (ndryshojnë) ose self (e marrin pronësinë). Funksionet pa self, si new(), thirren me Tipi::new().
EnglishEN
With impl you add methods to a struct. Methods take &self (read), &mut self (change) or self (take ownership). Functions without self, like new(), are called with Type::new().
Si ta mendosh
Si udhëzimet që i ngjit te pajisja: çfarë di të bëjë.
Lexoje në anglisht
Like the instructions stuck to an appliance: what it can do.
Shembull kodirust
impl Nxenes {
fn new(emri: &str) -> Self { Self { emri: emri.into(), nota: 0 } }
fn kaloi(&self) -> bool { self.nota >= 2 }
}