Rust

Result<T, E> (Ok, Err)

Në shqip përdoret i njëjti emër.

ShpjegimiSQ

Rust-i s'ka përjashtime. Një funksion që mund të dështojë kthen Result: Ok(vlera) kur shkon mirë, Err(gabimi) kur jo. Kështu gabimet janë pjesë e tipit dhe s'mund t'i harrosh.

EnglishEN

Rust has no exceptions. A function that can fail returns a Result: Ok(value) when it works, Err(error) when it doesn't. That way errors are part of the type and you can't forget them.

Si ta mendosh

Si një zarf që përmban ose çekun, ose letrën që shpjegon pse s'ka çek.

Lexoje në anglisht

Like an envelope holding either the cheque, or a letter explaining why there's no cheque.

Shembull kodirust

fn pjesto(a: f64, b: f64) -> Result<f64, String> {
    if b == 0.0 { Err("Pjesëtim me zero".into()) } else { Ok(a / b) }
}

Terma të lidhur