Whenever, by priority of possession, rights to the use of water for mining, agricultural, manufacturing, or other purposes have vested and accrued, and the same are recognized and acknowledged by the local customs, laws, and the decisions of courts, the possessors and owners of such vested rights shall be maintained and protected in the same; and the right-of-way for the construction of ditches and canals for the purposes herein specified is acknowledged and confirmed; but whenever any person, in the construction of any ditch or canal, injures or damages the possession of any settler on the public domain, the party committing such injury or damage shall be liable to the party injured for such injury or damage.