audunhalland / entrait

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

Revise how unimock types are exported #13

Closed audunhalland closed 1 year ago

audunhalland commented 2 years ago

Currently, the naming of generated unimock types is very inconsistent:

entrait unimock top-level item MockFn path
#[entrait(Foo)] fn foo() {} new module foo foo::Fn
#[entrait(Foo)] mod foo { fn bar() {} } flattened inside foo foo::bar::Fn
#[entrait] trait Foo { fn bar() } top-level struct Foo__bar

I wish to make these more consistent. The way Mockall does it seems better: always make some Mock* struct that represents the mockable trait.

This is the suggestion:

entrait unimock top-level item MockFn path notes
#[entrait(Foo)] fn foo() {} MockFoo MockFoo() the MockFn struct is defined as an empty tuple struct
#[entrait(Foo)] mod foo { fn bar() {} } MockFoo MockFoo::bar()
#[entrait] trait Foo { fn bar(); } MockFoo MockFoo::bar()

This should be part of the next major version of unimock (0.4), where the defaults will be changed from Foo__bar to Foo::bar()

audunhalland commented 1 year ago

Based on external feedback, the best way to do this is not to put any auto-generated names into scope, this is unhygienic. Instead, force the user name the API. This has already been done in Unimock 0.4. Unimock's API is #[unimock(api=MyApi)}. Entrait's API will be #[entrait(Foo, mock_api=MyMockApi)}.