nrxus / faux

Struct mocking library for Rust
https://nrxus.github.io/faux/
MIT License
420 stars 13 forks source link

Mocking traits #20

Open nrxus opened 4 years ago

nrxus commented 4 years ago

While there exist other libraries already capable of doing this, it might be nice to also provide that functionality here to not force the user to find yet another mocking framework on top of faux.

nrxus commented 3 years ago

I took a quick look at this and I would love to implement something that looks like:

#[faux::create]
trait MyTrait { /* some methods */ }

#[test]
fn test() {
    let mock = MyTrait::faux();
}

This however seems to only be possible if MyTrait is object safe which has a lot of limitations that I am not sure are desired.

Another issue I am having is that I don't know how should generics and associated items should work.

Since I don't really have a use case for this, I always mock structs, I don't really know what the desired behavior for some of these may be. I also don't know what limitations are acceptable and which ones would make the feature useless.

In short, this is theoretically feasible but I would love help understanding the requirements before I implement something that isn't valuable for those that need it.