  We compare the two duality theories of rank-metric codes proposed by Delsarte
and Gabidulin, proving that the former generalizes the latter. We also give an
elementary proof of MacWilliams identities for the general case of Delsarte
rank-metric codes. The identities which we derive are very easy to handle, and
allow us to re-establish in a very concise way the main results of the theory
of rank-metric codes first proved by Delsarte employing the theory of
association schemes and regular semilattices. We also show that our identities
imply as a corollary the original MacWilliams identities established by
Delsarte. We describe how the minimum and maximum rank of a rank-metric code
relate to the minimum and maximum rank of the dual code, giving some bounds and
characterizing the codes attaining them. Then we study optimal anticodes in the
rank metric, describing them in terms of optimal codes (namely, MRD codes). In
particular, we prove that the dual of an optimal anticode is an optimal
anticode. Finally, as an application of our results to a classical problem in
enumerative combinatorics, we derive both a recursive and an explicit formula
for the number of $k \times m$ matrices over a finite field with given rank and
$h$-trace.
