Implement Median for slice types with macro#274
Conversation
|
Dang is there really no good trait combo to describe "numbers"? I am a macro noob so I am gonna just play around with this one to learn it. |
|
I would say a number is described by the following ref: https://internals.rust-lang.org/t/please-can-we-add-a-basic-num-trait/16449 |
Wow yea. I guess we could shove that in an alias and boil it down to just the bare minimum requirement for the function (which could be what you have already), but we till wouldn't get away from the weird |
|
Either |
|
Yea, I still find the macro syntax wierd, but that is me just not knowing. I think the macro is essentially doing what the compiler would too for the trait bound? |
Yeah, the compiler will re-implement the trait for each type that ends up using it |
73beeaa to
da95db5
Compare
Attempting to remove the repeated logic here, but also trying to avoid the trait hell that is required for implementing
Medianin a generic way. I extracted the logic into a macro which is reusable for any type of interest to implementMediancc @nyonson