Skip to content

Use async fn in trait instead of BoxedFuture #11308

Closed
@tguichaoua

Description

@tguichaoua

What problem does this solve or what need does it fill?

async fn and return-position impl Trait in trait as been stabilized in 1.75 (rust-lang/rust#115822)

What solution would you like?

Replace usage of BoxedFuture in traits like AssetLoader by async fn.

fn load<'a>(
&'a self,
reader: &'a mut Reader,
settings: &'a Self::Settings,
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>>;

 async fn load<'a>( 
     &'a self, 
     reader: &'a mut Reader, 
     settings: &'a Self::Settings, 
     load_context: &'a mut LoadContext, 
 ) -> Result<Self::Asset, Self::Error>; 

What alternative(s) have you considered?

Keep using BoxedFuture with Box::pin(async move { /* */ });.

Current limitations

Because of the send bound problem, there is no way, yet, to add the Send bound on the returned future.
Alternatively it's possible to use impl Future + Send:

 fn load<'a>( 
     &'a self, 
     reader: &'a mut Reader, 
     settings: &'a Self::Settings, 
     load_context: &'a mut LoadContext, 
 ) -> impl Future<Output = Result<Self::Asset, Self::Error>> + Send + 'a; 

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AssetsLoad files from disk to use for things like images, models, and soundsC-FeatureA new feature, making something new possible

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions