These are chat archives for rust-lang/rust

25th
Mar 2016
Pete Hayes
@petehayes102
Mar 25 2016 09:56
Does anyone know if I can use compiler extensions to split a slice into discreet tokens? I am getting my arse kicked with binding to C variadic fns. I can use macros to pass variable nums of args, but if I want to do arbitrary transformations on those args, it’s not as straightforward.
Just after a quick answer in case anyone knows off the top of their heads
Otherwise I’ll rtfm on my own :)
Erik Hedvall
@Ogeon
Mar 25 2016 09:59
There's still the same problem with runtime vs compile time. Slices are a runtime thing, while macros are expanded at the syntax stage, before even types are known.
Pete Hayes
@petehayes102
Mar 25 2016 10:03
Hrm. I was really hoping I could find a nice way around this. Back to the too hard basket I guess.
Erik Hedvall
@Ogeon
Mar 25 2016 10:04
The only thing the compiler will eventually see (after type checking) is a dynamic (*const T, usize) pair, which says nothing about its content.
Pete Hayes
@petehayes102
Mar 25 2016 10:07
I was thinking I could create an enum to represent primitive c types, then in a macro, loop over the args and apply a match to return the transformed data to the c fn.
I just don’t like macros for operating on a struct. Much nicer to have an impl fn (I want to say method…but I know it’s not!)
Erik Hedvall
@Ogeon
Mar 25 2016 10:12
You would only be able to support a fixed maximal number of arguments, then, and you can't use a loop. I have to go, but you could possibly use a type to represent the length. Good luck!