Rusting of iron involves the formation of a layer of iron oxide on the surface of iron objects in the presence of moisture. Thus, for rusting to occur, water and oxygen are essential.
Oiling the surface of the iron objects protects the surface from direct contact from the atmospheric oxygen and moisture and prevents from rusting.