From 27b75fe424bcb838f1e4d9543212ff9f29838417 Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Sun, 18 Apr 2021 12:37:37 -0500 Subject: [PATCH] :pencil: docs: update README for bottom crates --- crates/always_equal/Cargo.toml | 2 +- crates/always_equal/README.md | 54 ++++++++++++++++++++++++++++++++++ crates/ptth_core/README.md | 4 +++ crates/ptth_core/src/lib.rs | 1 + 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 crates/always_equal/README.md create mode 100644 crates/ptth_core/README.md diff --git a/crates/always_equal/Cargo.toml b/crates/always_equal/Cargo.toml index 3f28828..d37c8b3 100644 --- a/crates/always_equal/Cargo.toml +++ b/crates/always_equal/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "always_equal" -version = "1.0.0" +version = "1.0.1" authors = ["Trish"] edition = "2018" license = "AGPL-3.0" diff --git a/crates/always_equal/README.md b/crates/always_equal/README.md new file mode 100644 index 0000000..bfd6738 --- /dev/null +++ b/crates/always_equal/README.md @@ -0,0 +1,54 @@ +# Always-Equal + +Always-Equal lets you wrap `PartialEq` implementations around +things that cannot be compared, like a `File`. + +To use Always-Equal, put these two conditional `use` +statements in your module: + +``` +#[cfg (test)] +use always_equal::test::AlwaysEqual; + +#[cfg (not (test))] +use always_equal::prod::AlwaysEqual; +``` + +Then wrap `AlwaysEqual` around anything that needs +PartialEq but can't possibly implement it: + +``` +use std::fs::File; +use always_equal::test::AlwaysEqual; + +#[derive (Debug, PartialEq)] +pub struct MyStruct { + pub b: bool, + pub i: i64, + pub file: AlwaysEqual , +} + +// In test code, you can create an empty wrapper using +// `testing_blank`, which is equal to any other wrapper: + +let expected = MyStruct { + b: true, + i: 0, + file: AlwaysEqual::testing_blank (), +}; + +# let my_file = File::open ("Cargo.toml").unwrap (); +let actual = MyStruct { + b: true, + i: 0, + file: my_file.into (), +}; + +assert_eq! (expected, actual); +``` + +This is implemented with `Option` in test mode. +In production mode, wrappers are never equal to any other +wrapper, and the `Option` is removed so that +`sizeof::> () == sizeof::` +_should_ be true. diff --git a/crates/ptth_core/README.md b/crates/ptth_core/README.md new file mode 100644 index 0000000..41a7e09 --- /dev/null +++ b/crates/ptth_core/README.md @@ -0,0 +1,4 @@ +# PTTH core + +Common code used by both `ptth_relay` and `ptth_server`. +Most users will want to use those binary crates directly. diff --git a/crates/ptth_core/src/lib.rs b/crates/ptth_core/src/lib.rs index fec27a5..b979643 100644 --- a/crates/ptth_core/src/lib.rs +++ b/crates/ptth_core/src/lib.rs @@ -1,6 +1,7 @@ //! # PTTH Core //! //! Common code used by both `ptth_relay` and `ptth_server`. +//! Most users will want to use those binary crates directly. #![warn (clippy::pedantic)]