Ainslie secured his place as one of Britain's most decorated Olympians.