Barrier Methods: Rusting may be prevented by stopping the water and oxygen getting to the iron with a barrier of grease, oil, paint or plastic.
Galvanising: (coating in zinc) also prevents water and oxygen getting to the iron, but with galvanising even if the barrier is broken the more reactive zinc corrodes before the less reactive iron. During the process, the zinc loses electrons to form zinc ions.