this post was submitted on 11 Apr 2024
56 points (98.3% liked)

Rust

5654 readers
57 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

[email protected]

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
top 9 comments
sorted by: hot top controversial new old
[–] [email protected] 12 points 4 months ago

How does it handle multiple potential outcomes? Example: unformat!("a {} b {} c", "a x b b y c") Would it return Some(("x b", "y")) or Some(("x", "b y"))?

[–] [email protected] 9 points 4 months ago* (last edited 4 months ago) (1 children)

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.txt with %Y-%M-%D.txt to {year: 2024, month: 04, day: 12}

I'll certainty be using this the next time I need anything like that in Rust though.

[–] [email protected] 7 points 4 months ago (1 children)

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.

[–] [email protected] 4 points 4 months ago

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 😁

[–] [email protected] 7 points 4 months ago

That's just brilliant.

[–] [email protected] 2 points 4 months ago

That’s really clever. I want to use it even though I haven’t been Rust‘ing lately

[–] [email protected] -1 points 4 months ago (1 children)

What am I missing? Seems like it just puts the parameter in Some?

Anti Commercial-AI license

[–] [email protected] 21 points 4 months ago* (last edited 4 months ago) (1 children)

You must've read that wrong.

The first example, but formatted differently:

let value = "My name is Rho.";
let result = unformat!("My {} is {}.", value);

Now, result contains:

Some(("name", "Rho"))

...because the words "name" and "Rho" in value happened to be at the position of the {}-slots in the unformat!()-pattern.

[–] [email protected] 5 points 4 months ago

Oh yeah! Thanks. It's been a long day.

Anti Commercial-AI license