Add a to_js method to the casting trait code in CodegenRust.py

Replace the manual checks and calls to transmute_copy in /layout/wrapper.rs with calls to to_js/

Fixes #3616