Rust

Operator overloading (Add, Mul)

Në shqip: Mbingarkimi i operatorëve në Rust

ShpjegimiSQ

Në Rust, operatorët janë trait-e: implemento std::ops::Add për tipin tënd dhe mund të shkruash a + b. Njësoj Mul (*), Index ([]), Neg (-) etj.

EnglishEN

In Rust, operators are traits: implement std::ops::Add for your type and you can write a + b. Likewise Mul (*), Index ([]), Neg (-) and so on.

Si ta mendosh

Si t'i mësosh kalkulatorit të mbledhë vektorë.

Lexoje në anglisht

Like teaching the calculator to add vectors.

Shembull kodirust

impl std::ops::Add for Vektor {
    type Output = Vektor;
    fn add(self, o: Vektor) -> Vektor { Vektor(self.0 + o.0, self.1 + o.1) }
}

Terma të lidhur