With static intro all of this is a macro, while loop, and a switch statement. A fraction of the complexity and you get editor help and typed holes. https://willcrichton.net/notes/type-safe-printf/ … https://github.com/deech/LambdaWorldCadiz2019-WhatFPCanLearnFromStaticIntrospection/blob/master/printf.nim …
Oh I see -- you're right, Rust doesn't give user-space macros access to type information. I've wanted this for a while though (see: https://willcrichton.net/notes/type-directed-metaprogramming-in-rust/ …).
-
-
However, with traits you can get a lot of mileage out of syntax-directed transformations. Rust's println impl doesn't introspect types. format!("{:?}", 3) expands to Arg(3, fmt::Debug) which then only type-checks if 3 implements Debug.
-
That's why Rust doesn't have %d or %s, just {} and {:?}. The Debug/Format traits take care of checking whether an object is convertible to a string.
- Show replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
cognitive psychology. PhD