ความไฮโซของ Rust 😅

Rust based บน functional programming ดังนั้นไม่มี feature function overloading ในภาษา แต่สามารถเขียนโค้ดให้ pass function ที่มี signature ต่างกันผ่าน function "to" ที่รับเพียงแค่ parameter เดียว คือ handler ที่เป็น trait Handler<Args>

trick คือ implement trait Handler<Args> ให้กับ function type แบบต่างๆ (ตามจำนวน parameter ที่เข้ามา) แล้วแปลงให้เป็น tuple form โดยผ่าน helper trait ชื่อ FormRequest และในขณะเดียวกันก็เลือก implement FormRequest กับ type ที่อยากจะ support

ทำให้สามารถบังคับได้ว่า function ที่ pass ให้กับ to จะต้องมี parameter type ตามที่ FormRequest support เท่านั้น! ซึ่งภาษาที่มี function overload ปกติต้องใช้ท่า interface + common method ซึ่งจะ enforce rule แบบนี้ไม่ได้

โหดมาก แต่ก็ elegant 😅