Skip to content

Commit c1de20a

Browse files
committed
Add readme-sync
1 parent bcd69ae commit c1de20a

File tree

4 files changed

+83
-25
lines changed

4 files changed

+83
-25
lines changed

README.md

+31-19
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ enum Example<T> {
9898
### Skipping fields
9999

100100
With a `skip` or `skip_inner` attribute fields can be skipped for traits
101-
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),
102-
[`PartialEq`](https://doc.rust-lang.org/core/cmp/trait.PartialEq.html) and [`Zeroize`].
101+
that allow it, which are: [`Debug`], [`Hash`], [`Ord`], [`PartialOrd`],
102+
[`PartialEq`] and [`Zeroize`].
103103

104104
```rust
105105
#[derive(DeriveWhere)]
@@ -151,7 +151,7 @@ assert_ne!(
151151
[`Zeroize`] has three options:
152152
- `crate`: an item-level option which specifies a path to the `zeroize`
153153
crate in case of a re-export or rename.
154-
- `drop`: an item-level option which implements [`Drop`](https://doc.rust-lang.org/core/ops/trait.Drop.html) and uses
154+
- `drop`: an item-level option which implements [`Drop`] and uses
155155
[`Zeroize`] to erase all data from memory.
156156
- `fqs`: a field -level option which will use fully-qualified-syntax instead
157157
of calling the [`zeroize`][`method@zeroize`] method on `self` directly.
@@ -184,15 +184,15 @@ assert_eq!(test.0, 0);
184184
### Supported traits
185185

186186
The following traits can be derived with derive-where:
187-
- [`Clone`](https://doc.rust-lang.org/core/clone/trait.Clone.html)
188-
- [`Copy`](https://doc.rust-lang.org/core/marker/trait.Copy.html)
187+
- [`Clone`]
188+
- [`Copy`]
189189
- [`Debug`]
190190
- [`Default`]
191-
- [`Eq`](https://doc.rust-lang.org/core/cmp/trait.Eq.html)
191+
- [`Eq`]
192192
- [`Hash`]
193-
- [`Ord`](https://doc.rust-lang.org/core/cmp/trait.Ord.html)
194-
- [`PartialEq`](https://doc.rust-lang.org/core/cmp/trait.PartialEq.html)
195-
- [`PartialOrd`](https://doc.rust-lang.org/core/cmp/trait.PartialOrd.html)
193+
- [`Ord`]
194+
- [`PartialEq`]
195+
- [`PartialOrd`]
196196
- [`Zeroize`]: Only available with the `zeroize` crate feature.
197197

198198
### Supported items
@@ -202,24 +202,23 @@ it's best to discourage usage that could be covered by std's `derive`. For
202202
example unit structs and enums only containing unit variants aren't
203203
supported.
204204

205-
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).
205+
Unions only support [`Clone`] and [`Copy`].
206206

207207
### `no_std` support
208208

209209
`no_std` support is provided by default.
210210

211211
## Crate features
212212

213-
- `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
214-
[`core::intrinsics::discriminant_value`](https://doc.rust-lang.org/core/intrinsics/fn.discriminant_value.html), which is what Rust does by
215-
default too. Without this feature [`transmute`](https://doc.rust-lang.org/core/mem/fn.transmute.html) is
216-
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),
217-
which is the underlying type.
218-
- `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
213+
- `nightly`: Implements [`Ord`] and [`PartialOrd`] with the help of
214+
[`core::intrinsics::discriminant_value`], which is what Rust does by
215+
default too. Without this feature [`transmute`] is used to convert
216+
[`Discriminant`] to a [`i32`], which is the underlying type.
217+
- `safe`: Implements [`Ord`] and [`PartialOrd`] manually. This is much
219218
slower, but might be preferred if you don't trust derive-where. It also
220-
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),
221-
[`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
222-
[`unreachable`](https://doc.rust-lang.org/core/macro.unreachable.html).
219+
replaces all cases of [`core::hint::unreachable_unchecked`] in [`Ord`],
220+
[`PartialEq`] and [`PartialOrd`], which is what std uses, with
221+
[`unreachable`].
223222
- `zeroize`: Allows deriving [`Zeroize`].
224223

225224
## MSRV
@@ -258,9 +257,22 @@ conditions.
258257
[CHANGELOG]: https://github.com/ModProg/derive-where/blob/main/CHANGELOG.md
259258
[LICENSE-MIT]: https://github.com/ModProg/derive-where/blob/main/LICENSE-MIT
260259
[LICENSE-APACHE]: https://github.com/ModProg/derive-where/blob/main/LICENSE-APACHE
260+
[`Clone`]: https://doc.rust-lang.org/core/clone/trait.Clone.html
261+
[`Copy`]: https://doc.rust-lang.org/core/marker/trait.Copy.html
261262
[`Debug`]: https://doc.rust-lang.org/core/fmt/trait.Debug.html
262263
[`Default`]: https://doc.rust-lang.org/core/default/trait.Default.html
264+
[`Drop`]: https://doc.rust-lang.org/core/ops/trait.Drop.html
265+
[`Eq`]: https://doc.rust-lang.org/core/cmp/trait.Eq.html
263266
[`Hash`]: https://doc.rust-lang.org/core/hash/trait.Hash.html
267+
[`Ord`]: https://doc.rust-lang.org/core/cmp/trait.Ord.html)
268+
[`PartialOrd`]: https://doc.rust-lang.org/core/cmp/trait.PartialOrd.html
269+
[`PartialEq`]: https://doc.rust-lang.org/core/cmp/trait.PartialEq.html
264270
[`Zeroize`]: https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html
265271
[`method@zeroize`]: https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html#tymethod.zeroize
272+
[`core::hint::unreachable_unchecked`]: https://doc.rust-lang.org/core/hint/fn.unreachable_unchecked.html
273+
[`core::intrinsics::discriminant_value`]: https://doc.rust-lang.org/core/intrinsics/fn.discriminant_value.html
274+
[`Discriminant`]: https://doc.rust-lang.org/core/mem/struct.Discriminant.html
275+
[`i32`]: https://doc.rust-lang.org/core/primitive.i32.html
276+
[`transmute`]: https://doc.rust-lang.org/core/mem/fn.transmute.html
277+
[`unreachable`]: https://doc.rust-lang.org/core/macro.unreachable.html
266278
[#27]: https://github.com/ModProg/derive-where/issues/27

non-msrv-tests/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ zeroize = ["derive-where/zeroize"]
1313
derive-where = { path = ".." }
1414

1515
[dev-dependencies]
16+
pulldown-cmark-to-cmark = "7"
17+
readme-sync = "0.2"
1618
trybuild = { version = "1", default-features = false }
1719
zeroize_ = { version = "1", package = "zeroize", default-features = false }
1820

non-msrv-tests/src/lib.rs

+32
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,35 @@ fn ui() {
1010
#[cfg(not(feature = "zeroize"))]
1111
TestCases::new().compile_fail("tests/ui/not-zeroize/*.rs");
1212
}
13+
14+
#[test]
15+
fn readme_sync() {
16+
use readme_sync::{assert_sync, CMarkDocs, CMarkReadme, Config, Package};
17+
18+
let package = Package::from_path("..".into()).unwrap();
19+
let config = Config::from_package_docs_rs_features(&package);
20+
let readme = CMarkReadme::from_package(&package).unwrap();
21+
let docs = CMarkDocs::from_package_and_config(&package, &config).unwrap();
22+
23+
let readme = readme
24+
.remove_badges_paragraph()
25+
.remove_documentation_section();
26+
27+
let docs = docs
28+
.increment_heading_levels()
29+
.add_package_title()
30+
.remove_codeblock_rust_test_tags()
31+
.use_default_codeblock_rust_tag()
32+
.remove_hidden_rust_code();
33+
34+
match std::env::var("WRITE_README") {
35+
Ok(value) if value == "1" => {
36+
let mut file = String::new();
37+
pulldown_cmark_to_cmark::cmark(docs.iter_events(), &mut file, None).unwrap();
38+
std::fs::write("../README.md", file).unwrap();
39+
}
40+
_ => (),
41+
}
42+
43+
assert_sync(&readme, &docs);
44+
}

src/lib.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,8 @@
248248
//!
249249
//! - `nightly`: Implements [`Ord`] and [`PartialOrd`] with the help of
250250
//! [`core::intrinsics::discriminant_value`], which is what Rust does by
251-
//! default too. Without this feature [`transmute`](core::mem::transmute) is
252-
//! used to convert [`Discriminant`](core::mem::Discriminant) to a [`i32`],
253-
//! which is the underlying type.
251+
//! default too. Without this feature [`transmute`] is used to convert
252+
//! [`Discriminant`] to a [`i32`], which is the underlying type.
254253
//! - `safe`: Implements [`Ord`] and [`PartialOrd`] manually. This is much
255254
//! slower, but might be preferred if you don't trust derive-where. It also
256255
//! replaces all cases of [`core::hint::unreachable_unchecked`] in [`Ord`],
@@ -294,11 +293,24 @@
294293
//! [CHANGELOG]: https://github.com/ModProg/derive-where/blob/main/CHANGELOG.md
295294
//! [LICENSE-MIT]: https://github.com/ModProg/derive-where/blob/main/LICENSE-MIT
296295
//! [LICENSE-APACHE]: https://github.com/ModProg/derive-where/blob/main/LICENSE-APACHE
297-
//! [`Debug`]: core::fmt::Debug
298-
//! [`Default`]: core::default::Default
299-
//! [`Hash`]: core::hash::Hash
296+
//! [`Clone`]: https://doc.rust-lang.org/core/clone/trait.Clone.html
297+
//! [`Copy`]: https://doc.rust-lang.org/core/marker/trait.Copy.html
298+
//! [`Debug`]: https://doc.rust-lang.org/core/fmt/trait.Debug.html
299+
//! [`Default`]: https://doc.rust-lang.org/core/default/trait.Default.html
300+
//! [`Drop`]: https://doc.rust-lang.org/core/ops/trait.Drop.html
301+
//! [`Eq`]: https://doc.rust-lang.org/core/cmp/trait.Eq.html
302+
//! [`Hash`]: https://doc.rust-lang.org/core/hash/trait.Hash.html
303+
//! [`Ord`]: https://doc.rust-lang.org/core/cmp/trait.Ord.html)
304+
//! [`PartialOrd`]: https://doc.rust-lang.org/core/cmp/trait.PartialOrd.html
305+
//! [`PartialEq`]: https://doc.rust-lang.org/core/cmp/trait.PartialEq.html
300306
//! [`Zeroize`]: https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html
301307
//! [`method@zeroize`]: https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html#tymethod.zeroize
308+
//! [`core::hint::unreachable_unchecked`]: https://doc.rust-lang.org/core/hint/fn.unreachable_unchecked.html
309+
//! [`core::intrinsics::discriminant_value`]: https://doc.rust-lang.org/core/intrinsics/fn.discriminant_value.html
310+
//! [`Discriminant`]: https://doc.rust-lang.org/core/mem/struct.Discriminant.html
311+
//! [`i32`]: https://doc.rust-lang.org/core/primitive.i32.html
312+
//! [`transmute`]: https://doc.rust-lang.org/core/mem/fn.transmute.html
313+
//! [`unreachable`]: https://doc.rust-lang.org/core/macro.unreachable.html
302314
//! [#27]: https://github.com/ModProg/derive-where/issues/27
303315
304316
// MSRV: needed to support a lower MSRV.

0 commit comments

Comments
 (0)