fixes for latest rust

uses enum FromPrimitive trait, drop use of cast::transmute, s/sys/mem/, etc...