Skip to content

Commit

Permalink
Add readme-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Jan 4, 2022
1 parent bcd69ae commit b44684d
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 25 deletions.
50 changes: 31 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ enum Example<T> {
### 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)]
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -202,24 +202,23 @@ 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

`no_std` support is provided by default.

## 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
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions non-msrv-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
32 changes: 32 additions & 0 deletions non-msrv-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
24 changes: 18 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`],
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit b44684d

Please sign in to comment.