Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce try_from_fn #15

Open
Fuuzetsu opened this issue Feb 13, 2025 · 1 comment
Open

Introduce try_from_fn #15

Fuuzetsu opened this issue Feb 13, 2025 · 1 comment

Comments

@Fuuzetsu
Copy link
Contributor

This is just from_fn that takes a function that returns Result<T, E> instead of T.

This means that when we have

StaticMap::from_fn(|v| foo(v))

and now foo becomes a Result, we could do

StaticMap::try_from_fn(|v| foo(v))?

For now the most ergonomic thing is

static_map! { v => foo(v)? }

which works but has all the usual annoyances of using a macro such as formatting problems.

One can't even go via array and try_map from stdlib and rewrap as it's still experimental.

Original ticket in enum-map: https://codeberg.org/xfix/enum-map/issues/148

@Fuuzetsu
Copy link
Contributor Author

I guess it'd use rust-lang/rust#84277 once that's stable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant