I know this is an old question and there are several answers for this using eigenvalues and matrix factorization but they have not taught in my matrix analysis course yet. Therefore, my question would be a different proof for the following:
$$\text{rank}(p)=\text{trace}(p)$$
where $p$ is an $n \times n$ matrix. The only thing that we are allowed to use is $p^2=p$ and the fact that $\text{trace}(AB)=\text{trace}(BA)=$ where $A,B$ are conformable matrices.
Please notice what I have asked before answering the question.