krojew / springtime

A framework for advanced Rust applications.
MIT License
78 stars 5 forks source link

Custom Constructors for Components causing an error with Futures #17

Open PainHex opened 2 weeks ago

PainHex commented 2 weeks ago

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

krojew commented 2 weeks ago

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.

PainHex commented 2 weeks ago

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?

krojew commented 2 weeks ago

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

PainHex commented 2 weeks ago

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?

krojew commented 2 weeks ago

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