gfx icon indicating copy to clipboard operation
gfx copied to clipboard

Auto-generate `empty` backend implementations

Open kvark opened this issue 7 years ago • 4 comments

Apparently, this is trivial with proc macros like https://crates.io/crates/mock_derive

kvark avatar Feb 04 '18 15:02 kvark

actually, it turns out to require nightly

kvark avatar Feb 09 '18 16:02 kvark

I think proc-macros are stable enough to use nowadays. Would a solution like mockall work?

GabrielMajeri avatar Apr 24 '20 18:04 GabrielMajeri

@GabrielMajeri no idea. Worth a try, perhaps?

kvark avatar Apr 25 '20 02:04 kvark

I've looked into it.

It has some bugs which will be fixed, but the major issue with it is that it would require us to keep two copies of each trait in the hal crate:

  • the original, documented and exposed by the crate
  • the other textual copy would be inside a mock! macro, because that's what's required to mock a trait on a struct:
pub trait Device<B: Backend> { /* ... */ }

mock! {
	pub FakeDevice {}

	trait Device<B: Backend> {
		/* copy & paste, except for docs and function bodies */
    }
}

I think it would just lead to more maintenance overhead.

GabrielMajeri avatar Apr 25 '20 14:04 GabrielMajeri