Oddbean new post about | logout
 i try to use try_from/unwrap consistently when converting between numeric type sizes in rust, but it's just so much ceremony, just yoloing an `as` tempts me every time, especially for conversions between say u64 and usize 
 @25b22fbb I first saw this in ttf-parser. A trait that allows safe casting to usize that fails at compile time if target_pointer_width is too small. If you intend to only target 64-bit platforms an adaptation of it might be a nice ergonomics improvement.

I tweaked the trait/fn name to SafeFrom/safe_from when I pulled it into my own project.

https://github.com/RazrFalcon/ttf-parser/blob/e052dbb1627847cb813620637cf97ac8b6270338/src/parser.rs#L155