DEV Community

Discussion on: How type conversions work in Rust

vorfeedcanal profile image

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.

timclicks profile image
Tim McNamara Author

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