image-rs / imageproc

Image processing operations
MIT License
736 stars 144 forks source link

Add docs.rs feature description #610

Closed sunsided closed 3 months ago

sunsided commented 3 months ago

This adds the #[cfg_attr(docsrs, doc(cfg(feature = "...")))] markers to inform docs.rs about feature conditions. It looks somewhat like this;

image

Since this is a feature that only works with docs.rs, it's gated by the #![cfg_attr(docsrs, feature(doc_cfg))] attribute in lib.rs.

theotherphil commented 3 months ago

This is great, thanks - I wasn't aware of this feature.

Before I merge this PR please can you either add this attribute to the rest of the feature-enabled functions in this crate or create a GitHub issue to track that someone needs to do so.

sunsided commented 3 months ago

I should have covered the relevant ones, but I'll have another look. Specifically I skipped the example code as that won't be in the docs either, ignored the feature switches that are explicitly in code for the same reason, and skipped everything that is purely test related.

I'll have another look though.

theotherphil commented 3 months ago

Ah, the other uses I was thinking of are actually hidden inside functions, e.g. https://github.com/image-rs/imageproc/blob/44bbf5e7efd8d9de41ffafc2be2a0696cfecfb4b/src/contrast.rs#L245

Maybe there are no missed uses then!

sunsided commented 3 months ago

Hum, I think my IDE tricked me and there are indeed some missing. I'll push to the branch again and re-open the PR then. ✌🏼

Edit: in #612

fintelia commented 3 months ago

I believe you can also do #![cfg_attr(docsrs, feature(doc_auto_cfg))] to automatically apply the annotation everywhere

theotherphil commented 3 months ago

Thanks @fintelia - definitely worth a look