  We define a class of automorphisms of rational function fields of finite
characteristic and employ these to construct different types of optimal linear
rank-metric codes. The first construction is of generalized Gabidulin codes
over rational function fields. Reducing these codes over finite fields, we
obtain maximum rank distance (MRD) codes which are not equivalent to
generalized twisted Gabidulin codes. We also construct optimal Ferrers diagram
rank-metric codes which settles further a conjecture by Etzion and Silberstein.
