There is no rule. Generally, the '-ing' form appears in the subject position (as in your first sentence). '-Ing' suggests the ongoing activity, while 'to' suggests the potentiality of the action, and most usages are based on that difference.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.