Was tinkering with the Rust concept of 'forcing' a larger size integer type into a smaller size type* and I could not figure out why the compiler seemed to keep complaining even after I applied the suggested hint.

https://gist.github.com/rust-play/53ff3858f9fbdaf5d1dfbd9adaec7f3d

x + y is the return expression** and I needed to call try_into() on the whole thing and the following is (now) obviously calling it on the y.

x + y.try_into().unwrap()

So now this works...

(x + y).try_into().unwrap()

* - I would not program this way, trying to stuff something larger into something smaller, but just for the exercise of it

** - is 'expression' the correct term here?

#RustLanguage #programming

Code shared from the Rust Playground

Code shared from the Rust Playground. GitHub Gist: instantly share code, notes, and snippets.

Gist
@snacktraces you can cast primitive types in rust with `as`. I think it will do the as c would do. => https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=57672b01939c03f10d905444459dde1e
Rust Playground

A browser interface to the Rust compiler to experiment with the language