nrxus / faux

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

Unsafe as a feature #4

Closed nrxus closed 3 years ago

nrxus commented 4 years ago

Writing unsafe on every mock is a bit annoying.

What if we added a feature called unsafe or i-know-faux-is-unsafe-so-hush that if turned on exposed the mocking methods as "safe" since the user has already opted-in the unsafety at the crate level.

TedDriggs commented 4 years ago

What if you added reckless_then as a "safe" version of then which just lies about the safety? You can gate the exposure of that method on a crate feature, and that way one crate turning it on won't cause other crates in the dependency graph to experience any behavior changes.

nrxus commented 4 years ago

Do you mind linking me documentation on how feature flags poison through cyclic dependencies? My google-fu is failing me.

TedDriggs commented 4 years ago

crate A

[dependencies]
crate-b = { version = "0.1.0", features = ["foo"] }
crate-c = "1.1.0"

crate C

[dependencies]
crate-b = { version = "0.1.0", features = ["baz"] }

At this point, crate A would see both foo and baz features enabled. That's why features are supposed to always be additive, and to avoid being mutually exclusive whenever possible.

nrxus commented 4 years ago

Ah!

That makes sense now. Hmm I am not a huge fan of reckless_then but I will consider it as I think of alternatives. I do not think this is a very high priority issue anyway, explicit unsafe will do for now.

nrxus commented 3 years ago

faux can now handle a lot more code with safe Rust so this is no longer needed.