In the case of finding yourself within a few paces and under threat of a predator:
I have one personal experience with a man with malicious sexual intentions following, talking, making body contact, shying away, being told to fuck off, and continuing to follow me while unbuckling his belt (I am a male).
The solution (while I could have ran, I was not content with the chance of being caught off balance or seeing where I live or anything like that) came in holding my ground, raising a clenched fist and very present-mindedly yet firmly agressive, stating “I will fucking hurt you”.
It seems likely that making that kind of explicit statement triggers a cost-benefit analysis in a predatory mind who is looking for pleasure (maybe both sexual and sadistic) without physically engaging them: verbally letting them know that you are ready, capable, and that any attempt will involve YOU hurting THEM.
Think about things you don’t know how to do. :)