Async version of the From Trait

I was wondering if there's an Async version of the From trait; does anyone know of a crate with such functionality? I quickly searched in crates.io, but couldn't find anything.

Otherwise I will start coding it :smiley:

Generally, I think that if a conversion requires something as complicated as async, then it probably shouldn't be using the From trait. It's mainly intended for simple conversions. How about defining an ordinary method on your type instead of putting it in a trait?

2 Likes

The thing is that I'm already using the From trait to convert from enum A variant to enum B variant, it just happens that I want to introduce a new variant that will need some additional data to be fetched when being converted to it's corresponding enum B variant, hence why an Async version of the trait would fit nicely for the refactoring :confused:

I still think that an ordinary async method would be more appropriate.

5 Likes

I ended up going with an async method as you suggested, Alice, since I needed to pass it the function that would fetch the additional required data.