Rust

Type casting with as

Në shqip: Konvertimi i tipeve me as

ShpjegimiSQ

Rust s'i konverton numrat vetë — duhet ta shkruash: x as f64. as mund të presë vlerat (300 as u8 = 44); për konvertim të sigurt përdor try_into() që kthen Result.

EnglishEN

Rust doesn't convert numbers by itself — you write it out: x as f64. as can truncate values (300 as u8 = 44); for safe conversion use try_into(), which returns a Result.

Si ta mendosh

Si të ndërrosh monedhën te sporteli, me faturë.

Lexoje në anglisht

Like exchanging currency at the counter, with a receipt.

Shembull kodirust

let a: i32 = 7;
let b = a as f64 / 2.0;            // 3.5
let c: u8 = 300_i32.try_into().unwrap_or(255);

Terma të lidhur