We extend the notion of locality from the Hamming metric to the rank and subspace metrics. First, we present a construction of a class of array codes with locality constraints in the rank metric. Our motivation for constructing such codes stems from designing codes for efficient data recovery from correlated and/or mixed (i.e., complete and partial) failures in distributed storage systems. Our proposed construction achieves the Singleton-like upper bound on the minimum rank distance of (linear) codes with 'rank-locality' constraints for a broad range of parameters. Second, we present a class of subspace codes (also known as codes in projective space) with locality constraints in the subspace metric. We show that a subspace code with locality can be easily constructed from a rank-metric code with locality by using the lifting method proposed by Silva et al. One potential application of such codes is for distributed storage systems, wherein nodes are connected over a network that can introduce errors and erasures.