slab icon indicating copy to clipboard operation
slab copied to clipboard

Move unsafe code behind a (enabled by default) feature flag

Open notgull opened this issue 1 year ago • 4 comments

I am using this crate in a crate that is forbid(unsafe_code), where I would like to reduce the amount of unsafe code in my dependency tree. The unsafe code currently in this crate could be eliminated.

I propose an unchecked feature. When enabled, the get_unchecked and other methods that require unsafe are exposed. When disabled, this crate becomes forbid(unsafe_code). This feature would be enabled by default to prevent breaking changes.

I am willing to implement this feature myself.

notgull avatar Aug 16 '22 01:08 notgull

features should be additive and we cannot use features to disable APIs.

taiki-e avatar Aug 16 '22 05:08 taiki-e

Oh, sorry, you seem to be suggesting an additive feature that is enabled by default. However, note that for users using slab with default-features = false the approach you suggest is also a breaking change.

taiki-e avatar Aug 16 '22 06:08 taiki-e

Hmm, that's a pickle. I'd rather not introduce a breaking change unless there's already an upcoming breaking change planned. I guess I could just write the PR and wait for version 0.5 for it to be merged.

notgull avatar Aug 16 '22 13:08 notgull

(At this time there are no plans for 0.5...)

taiki-e avatar Aug 16 '22 13:08 taiki-e

We are unlikely to have a breaking release any time soon, so your PR would probably sit around for at least a year. Additionally, I don't really think there's any value in a feature like this. None of the internals use unsafe besides the methods that are unsafe to call, so if you don't call those, you aren't using any unsafe code.

Darksonn avatar Aug 16 '22 19:08 Darksonn