springtime icon indicating copy to clipboard operation
springtime copied to clipboard

Custom Constructors for Components causing an error with Futures

Open PainHex opened this issue 1 year ago • 5 comments

I have a custom constructor with a very basic example, but it consistently results in the following error:

#[derive(Component)] | ^^^^^^^^^ | | | Result<HandlebarsEngineImpl, Arc<dyn StdError + Send + Sync>> is not a future | this call returns Result<HandlebarsEngineImpl, Arc<dyn StdError + Send + Sync>> | = help: the trait Future is not implemented for Result<HandlebarsEngineImpl, Arc<dyn StdError + Send + Sync>>, which is required by Result<HandlebarsEngineImpl, Arc<dyn StdError + Send + Sync>>: IntoFuture = note: Result<HandlebarsEngineImpl, Arc<dyn StdError + Send + Sync>> must be a future or must implement IntoFuture to be awaited = note: required for Result<HandlebarsEngineImpl, Arc<dyn StdError + Send + Sync>> to implement IntoFuture

PainHex avatar Jun 17 '24 15:06 PainHex

You seem to be using the async feature while your constructor doesn't return a future. Either turn off async or return a future, even trivial one.

krojew avatar Jun 17 '24 16:06 krojew

Thank you! It looks like that was exactly the issue. I ultimately changed my implementation, but I might open a PR with this as an example, if thats okay?

PainHex avatar Jun 17 '24 19:06 PainHex

PRs are always welcome. Will this example by different than https://github.com/krojew/springtime/blob/master/springtime-di/examples/06-custom-constructor.rs?

krojew avatar Jun 17 '24 19:06 krojew

It would be almost identical, aside from the fact that the constructor would return a future.

Out of curiosity, without hi-jacking this thread, is there a big benefit to using the Async flag?

PainHex avatar Jun 17 '24 19:06 PainHex

Not everything can be constructed synchronously, so async is required in such cases.

krojew avatar Jun 18 '24 04:06 krojew

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 31 '25 21:01 stale[bot]