audunhalland / entrait

Loosely coupled Rust application design made easy
86 stars 3 forks source link

Entrait 0.5 plans #9

Closed audunhalland closed 1 year ago

audunhalland commented 2 years ago

Change default behaviour for mockability

In entrait 0.5, I want more focus on dependency inversion and less focus on mocking out every single function.

The main advantages of the entrait pattern for functions are:

  1. Abstracting away the application, all business logic is available as extension methods on Impl<T>
  2. Each function only specifies its direct dependencies. The trait engine automatically takes care of verifying that transitive dependencies are fulfilled.

Support for mocking every little function when unimock is enabled is potentially generating a lot more code than necessary. Instead, by default, we could try to generate a very simple impl<T> Trait for T where T: Dependencies that could cover both Impl<T> and mocked environments. Mocking a simple function will become opt-in, with something like #[entrait(Foo, mock)]).

Mock support should be enabled by default on inverted dependencies - the ones that have no local implementation.

Rename async-trait to boxed-futures.

async-trait is just an implementation detail on the way to get boxed futures, and this does not need to be exposed.

~## Investigate trait redesign~ ~https://github.com/audunhalland/entrait/issues/11~