Here, WithPort returns a closure. A closure is an anonymous function that references variables from outside its body; in this case, the port variable. The closure respects the Option type and implements the port-validation logic. Each config field requires creating a public function (that starts with the With prefix by convention) containing similar logic: validating inputs if needed and updating the config struct.
标签:11,closure,function,pattern,functional,mistakes,port From: https://www.cnblogs.com/zhangzhihui/p/18015107