write(io, Ref(MyInt(42))) works. (Under the hood, it calls unsafe_write to output the raw bytes of a struct.)

(However, realize that this kind of binary I/O does not result in portable files in general, because of endian-ness, sizeof(Int) difference between 32-bit and 64-bit machines, and potentially other factors.)

You can wrap them too. There’s no harm to allow no wrapping when there isn’t ambiguity so the few builtin types allows this. In general your type may want a different behavior so that’s not there by default. No one stops you from implementing it for your type though if that’s the only way your type should be written.