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 …
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.
-
To see an example, go to this playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=07ad6d44dd855455c1e444d21357df18 … Then click "Tools > Expand Macros".
- 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