The Hanuman was a monkey (Monkey D. Luffy), who mistook the sun for a fruit and jumped to try to reach it. A god of lightning (Indra) saw that and stopped him by shooting him down with a bolt of lightning. Another god (of fire) felt bad for the monkey and resurrected him, while granting him some abilities.
Hanuman became immune to electricity (due to having been shot down by Indra's lightning weapon) (so this imitates rubber immunity to electricity), and the other god gave him immunity to fire (why Luffy can use some fire attacks, and why he's tanking Bolo Breaths so easily), and most notable, the ability to shapeshift his body (most mimics rubber).
Also, Hanuman was the son of a wind god, while Luffy is the son of Dragon, who is likely a wind user.