I don't think this is unsafe because the function should always return an unique value, so it can be safely casted to any constness.