c/rust · by testeronious@lemmy.world · 2y`unfmt`: A compile-time pattern matching library that reverses the interpolation process of `format!`. https://github.com/mathematic-inc/unfmt58 points · 9 comments · view on lemmy.world
9 Comments
livingcoder@programming.dev · 12 pts · 2y
How does it handle multiple potential outcomes? Example:
unformat!("a {} b {} c", "a x b b y c")Would it returnSome(("x b", "y"))orSome(("x", "b y"))?voklen@programming.dev · 9 pts · 2y
I love the concept! I recently wanted something just like this for a Flutter app I was making to parse a filename into a user defined format i.e.
2024-04-12.txtwith%Y-%M-%D.txtto{year: 2024, month: 04, day: 12}I'll certainty be using this the next time I need anything like that in Rust though.
fhoekstra@programming.dev · 7 pts · 2y
Off-topic, but I recognise your name. Thank you for the Daily Diary App! I'm a huge fan, I use it every day for my gratitude routine.
voklen@programming.dev · 4 pts · 2y
Wow, I've never had anyone recognise my name for something I've made! Thank you so much and I'm glad you're enjoying it 😁
myotherself@lemmings.world · 7 pts · 2y
That's just brilliant.
avonarret1@programming.dev · 2 pts · 2y
That’s really clever. I want to use it even though I haven’t been Rust‘ing lately
onlinepersona@programming.dev · -1 pts · 2y
What am I missing? Seems like it just puts the parameter in
Some?Anti Commercial-AI license
Ephera@lemmy.ml · 21 pts · 2y
You must've read that wrong.
The first example, but formatted differently:
Now,
resultcontains:...because the words "name" and "Rho" in
valuehappened to be at the position of the {}-slots in the unformat!()-pattern.onlinepersona@programming.dev · 5 pts · 2y
Oh yeah! Thanks. It's been a long day.
Anti Commercial-AI license