DEV Community

Discussion on: How type conversions work in Rust

Collapse
 
vorfeedcanal profile image
VorfeedCanal

doc.rust-lang.org/nomicon/casts.html

casting from a larger integer to a smaller integer (e.g. u32 -> u8) will truncate
casting from a smaller integer to a larger integer (e.g. u8 -> u32) will
zero-extend if the source is unsigned
sign-extend if the source is signed

Someone is wrong. Either nomicon or this article.

Collapse
 
timclicks profile image
Tim McNamara

I'm wrong. I'll make some changes to the post.