Rust

Methods: self, &self, &mut self

Në shqip: Metodat dhe self në Rust

ShpjegimiSQ

Te impl, metodat marrin &self (vetëm lexojnë), &mut self (ndryshojnë) ose self (e konsumojnë objektin). Funksionet pa self, si new(), thirren me Tipi::new().

EnglishEN

In impl, methods take &self (read only), &mut self (modify) or self (consume the object). Functions without self, like new(), are called with Type::new().

Si ta mendosh

Si dallimi mes shikimit, rregullimit dhe dhurimit të një sendi.

Lexoje në anglisht

Like the difference between looking at, fixing, and giving away an item.

Shembull kodirust

impl Llogari {
    fn new() -> Self { Self { bilanci: 0 } }
    fn bilanci(&self) -> i64 { self.bilanci }
    fn depozito(&mut self, x: i64) { self.bilanci += x; }
}

Terma të lidhur