diff --git a/README.md b/README.md index 658ac62f..96772d64 100644 --- a/README.md +++ b/README.md @@ -98,8 +98,8 @@ enum Example { ### Skipping fields With a `skip` or `skip_inner` attribute fields can be skipped for traits -that allow it, which are: [`Debug`], [`Hash`], [`Ord`](https://doc.rust-lang.org/core/cmp/trait.Ord.html), [`PartialOrd`](https://doc.rust-lang.org/core/cmp/trait.PartialOrd.html), -[`PartialEq`](https://doc.rust-lang.org/core/cmp/trait.PartialEq.html) and [`Zeroize`]. +that allow it, which are: [`Debug`], [`Hash`], [`Ord`], [`PartialOrd`], +[`PartialEq`] and [`Zeroize`]. ```rust #[derive(DeriveWhere)] @@ -151,7 +151,7 @@ assert_ne!( [`Zeroize`] has three options: - `crate`: an item-level option which specifies a path to the `zeroize` crate in case of a re-export or rename. -- `drop`: an item-level option which implements [`Drop`](https://doc.rust-lang.org/core/ops/trait.Drop.html) and uses +- `drop`: an item-level option which implements [`Drop`] and uses [`Zeroize`] to erase all data from memory. - `fqs`: a field -level option which will use fully-qualified-syntax instead of calling the [`zeroize`][`method@zeroize`] method on `self` directly. @@ -184,15 +184,15 @@ assert_eq!(test.0, 0); ### Supported traits The following traits can be derived with derive-where: -- [`Clone`](https://doc.rust-lang.org/core/clone/trait.Clone.html) -- [`Copy`](https://doc.rust-lang.org/core/marker/trait.Copy.html) +- [`Clone`] +- [`Copy`] - [`Debug`] - [`Default`] -- [`Eq`](https://doc.rust-lang.org/core/cmp/trait.Eq.html) +- [`Eq`] - [`Hash`] -- [`Ord`](https://doc.rust-lang.org/core/cmp/trait.Ord.html) -- [`PartialEq`](https://doc.rust-lang.org/core/cmp/trait.PartialEq.html) -- [`PartialOrd`](https://doc.rust-lang.org/core/cmp/trait.PartialOrd.html) +- [`Ord`] +- [`PartialEq`] +- [`PartialOrd`] - [`Zeroize`]: Only available with the `zeroize` crate feature. ### Supported items @@ -202,7 +202,7 @@ it's best to discourage usage that could be covered by std's `derive`. For example unit structs and enums only containing unit variants aren't supported. -Unions only support [`Clone`](https://doc.rust-lang.org/core/clone/trait.Clone.html) and [`Copy`](https://doc.rust-lang.org/core/marker/trait.Copy.html). +Unions only support [`Clone`] and [`Copy`]. ### `no_std` support @@ -210,16 +210,15 @@ Unions only support [`Clone`](https://doc.rust-lang.org/core/clone/trait.Clone.h ## Crate features -- `nightly`: Implements [`Ord`](https://doc.rust-lang.org/core/cmp/trait.Ord.html) and [`PartialOrd`](https://doc.rust-lang.org/core/cmp/trait.PartialOrd.html) with the help of - [`core::intrinsics::discriminant_value`](https://doc.rust-lang.org/core/intrinsics/fn.discriminant_value.html), which is what Rust does by - default too. Without this feature [`transmute`](https://doc.rust-lang.org/core/mem/fn.transmute.html) is - used to convert [`Discriminant`](https://doc.rust-lang.org/core/mem/struct.Discriminant.html) to a [`i32`](https://doc.rust-lang.org/core/primitive.i32.html), - which is the underlying type. -- `safe`: Implements [`Ord`](https://doc.rust-lang.org/core/cmp/trait.Ord.html) and [`PartialOrd`](https://doc.rust-lang.org/core/cmp/trait.PartialOrd.html) manually. This is much +- `nightly`: Implements [`Ord`] and [`PartialOrd`] with the help of + [`core::intrinsics::discriminant_value`], which is what Rust does by + default too. Without this feature [`transmute`] is used to convert + [`Discriminant`] to a [`i32`], which is the underlying type. +- `safe`: Implements [`Ord`] and [`PartialOrd`] manually. This is much slower, but might be preferred if you don't trust derive-where. It also - replaces all cases of [`core::hint::unreachable_unchecked`](https://doc.rust-lang.org/core/hint/fn.unreachable_unchecked.html) in [`Ord`](https://doc.rust-lang.org/core/hint/fn.unreachable_unchecked.html), - [`PartialEq`](https://doc.rust-lang.org/core/cmp/trait.PartialEq.html) and [`PartialOrd`](https://doc.rust-lang.org/core/cmp/trait.PartialOrd.html), which is what std uses, with - [`unreachable`](https://doc.rust-lang.org/core/macro.unreachable.html). + replaces all cases of [`core::hint::unreachable_unchecked`] in [`Ord`], + [`PartialEq`] and [`PartialOrd`], which is what std uses, with + [`unreachable`]. - `zeroize`: Allows deriving [`Zeroize`]. ## MSRV @@ -258,9 +257,22 @@ conditions. [CHANGELOG]: https://github.com/ModProg/derive-where/blob/main/CHANGELOG.md [LICENSE-MIT]: https://github.com/ModProg/derive-where/blob/main/LICENSE-MIT [LICENSE-APACHE]: https://github.com/ModProg/derive-where/blob/main/LICENSE-APACHE +[`Clone`]: https://doc.rust-lang.org/core/clone/trait.Clone.html +[`Copy`]: https://doc.rust-lang.org/core/marker/trait.Copy.html [`Debug`]: https://doc.rust-lang.org/core/fmt/trait.Debug.html [`Default`]: https://doc.rust-lang.org/core/default/trait.Default.html +[`Drop`]: https://doc.rust-lang.org/core/ops/trait.Drop.html +[`Eq`]: https://doc.rust-lang.org/core/cmp/trait.Eq.html [`Hash`]: https://doc.rust-lang.org/core/hash/trait.Hash.html +[`Ord`]: https://doc.rust-lang.org/core/cmp/trait.Ord.html +[`PartialOrd`]: https://doc.rust-lang.org/core/cmp/trait.PartialOrd.html +[`PartialEq`]: https://doc.rust-lang.org/core/cmp/trait.PartialEq.html [`Zeroize`]: https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html [`method@zeroize`]: https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html#tymethod.zeroize +[`core::hint::unreachable_unchecked`]: https://doc.rust-lang.org/core/hint/fn.unreachable_unchecked.html +[`core::intrinsics::discriminant_value`]: https://doc.rust-lang.org/core/intrinsics/fn.discriminant_value.html +[`Discriminant`]: https://doc.rust-lang.org/core/mem/struct.Discriminant.html +[`i32`]: https://doc.rust-lang.org/core/primitive.i32.html +[`transmute`]: https://doc.rust-lang.org/core/mem/fn.transmute.html +[`unreachable`]: https://doc.rust-lang.org/core/macro.unreachable.html [#27]: https://github.com/ModProg/derive-where/issues/27 diff --git a/non-msrv-tests/Cargo.toml b/non-msrv-tests/Cargo.toml index 4a6179a8..cf2de3b8 100644 --- a/non-msrv-tests/Cargo.toml +++ b/non-msrv-tests/Cargo.toml @@ -13,6 +13,8 @@ zeroize = ["derive-where/zeroize"] derive-where = { path = ".." } [dev-dependencies] +pulldown-cmark-to-cmark = "7" +readme-sync = "0.2" trybuild = { version = "1", default-features = false } zeroize_ = { version = "1", package = "zeroize", default-features = false } diff --git a/non-msrv-tests/src/lib.rs b/non-msrv-tests/src/lib.rs index d0d7fc20..9fe73de7 100644 --- a/non-msrv-tests/src/lib.rs +++ b/non-msrv-tests/src/lib.rs @@ -10,3 +10,35 @@ fn ui() { #[cfg(not(feature = "zeroize"))] TestCases::new().compile_fail("tests/ui/not-zeroize/*.rs"); } + +#[test] +fn readme_sync() { + use readme_sync::{assert_sync, CMarkDocs, CMarkReadme, Config, Package}; + + let package = Package::from_path("..".into()).unwrap(); + let config = Config::from_package_docs_rs_features(&package); + let readme = CMarkReadme::from_package(&package).unwrap(); + let docs = CMarkDocs::from_package_and_config(&package, &config).unwrap(); + + let readme = readme + .remove_badges_paragraph() + .remove_documentation_section(); + + let docs = docs + .increment_heading_levels() + .add_package_title() + .remove_codeblock_rust_test_tags() + .use_default_codeblock_rust_tag() + .remove_hidden_rust_code(); + + match std::env::var("WRITE_README") { + Ok(value) if value == "1" => { + let mut file = String::new(); + pulldown_cmark_to_cmark::cmark(docs.iter_events(), &mut file, None).unwrap(); + std::fs::write("../README.md", file).unwrap(); + } + _ => (), + } + + assert_sync(&readme, &docs); +} diff --git a/src/lib.rs b/src/lib.rs index d22e9001..163e1135 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -248,9 +248,8 @@ //! //! - `nightly`: Implements [`Ord`] and [`PartialOrd`] with the help of //! [`core::intrinsics::discriminant_value`], which is what Rust does by -//! default too. Without this feature [`transmute`](core::mem::transmute) is -//! used to convert [`Discriminant`](core::mem::Discriminant) to a [`i32`], -//! which is the underlying type. +//! default too. Without this feature [`transmute`] is used to convert +//! [`Discriminant`] to a [`i32`], which is the underlying type. //! - `safe`: Implements [`Ord`] and [`PartialOrd`] manually. This is much //! slower, but might be preferred if you don't trust derive-where. It also //! replaces all cases of [`core::hint::unreachable_unchecked`] in [`Ord`], @@ -294,11 +293,24 @@ //! [CHANGELOG]: https://github.com/ModProg/derive-where/blob/main/CHANGELOG.md //! [LICENSE-MIT]: https://github.com/ModProg/derive-where/blob/main/LICENSE-MIT //! [LICENSE-APACHE]: https://github.com/ModProg/derive-where/blob/main/LICENSE-APACHE -//! [`Debug`]: core::fmt::Debug -//! [`Default`]: core::default::Default -//! [`Hash`]: core::hash::Hash +//! [`Clone`]: https://doc.rust-lang.org/core/clone/trait.Clone.html +//! [`Copy`]: https://doc.rust-lang.org/core/marker/trait.Copy.html +//! [`Debug`]: https://doc.rust-lang.org/core/fmt/trait.Debug.html +//! [`Default`]: https://doc.rust-lang.org/core/default/trait.Default.html +//! [`Drop`]: https://doc.rust-lang.org/core/ops/trait.Drop.html +//! [`Eq`]: https://doc.rust-lang.org/core/cmp/trait.Eq.html +//! [`Hash`]: https://doc.rust-lang.org/core/hash/trait.Hash.html +//! [`Ord`]: https://doc.rust-lang.org/core/cmp/trait.Ord.html +//! [`PartialOrd`]: https://doc.rust-lang.org/core/cmp/trait.PartialOrd.html +//! [`PartialEq`]: https://doc.rust-lang.org/core/cmp/trait.PartialEq.html //! [`Zeroize`]: https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html //! [`method@zeroize`]: https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html#tymethod.zeroize +//! [`core::hint::unreachable_unchecked`]: https://doc.rust-lang.org/core/hint/fn.unreachable_unchecked.html +//! [`core::intrinsics::discriminant_value`]: https://doc.rust-lang.org/core/intrinsics/fn.discriminant_value.html +//! [`Discriminant`]: https://doc.rust-lang.org/core/mem/struct.Discriminant.html +//! [`i32`]: https://doc.rust-lang.org/core/primitive.i32.html +//! [`transmute`]: https://doc.rust-lang.org/core/mem/fn.transmute.html +//! [`unreachable`]: https://doc.rust-lang.org/core/macro.unreachable.html //! [#27]: https://github.com/ModProg/derive-where/issues/27 // MSRV: needed to support a lower MSRV.