How to store async functions in a vector?

I want to store a few function pointers following the similar interface (all are asyncs, have the same arguments and the same return value) in a vector, so that I could iterate over each of those and call them with my arguments and get results.
playground

struct Profile;
async fn get_steam_profile_info(id: &str) -> Result<Profile, ()> { Ok(Profile) }
async fn get_fortnite_profile_info(id: &str) -> Result<Profile, ()> { Ok(Profile) }

fn main() {
    let fetchers = vec![get_steam_profile_info, get_fortnite_profile_info];
}

Something like this works:

struct Profile;

use futures::future::{Future, BoxFuture};
type ProfileInfoGetter = fn(&str) -> BoxFuture<'_, Result<Profile, ()>>;
async fn get_steam_profile_info(id: &str) -> Result<Profile, ()> {
    Ok(Profile)
}
async fn get_fortnite_profile_info(id: &str) -> Result<Profile, ()> {
    Ok(Profile)
}

fn main() {
    let fetchers: Vec<ProfileInfoGetter> =
        vec![
            |id| Box::pin(get_steam_profile_info(id)),
            |id| Box::pin(get_fortnite_profile_info(id)),
        ];
}

Note that this may be a somewhat nontrivial task in and by itself in case you want to call the async fns in parallel.

Thank you very much for your answer. I'll try this out.
And no, I need these functions to be called sequentially, not, want to call each one of them until I get an Ok result, so your solution should work perfectly.

Check out this thread:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.