How to eliminate boilterplate pattern matching with same branches?

Maybe this topic is what you are looking for? Auto generate .as_XYZ for enum - #3 by moy2010