From 3a2a6b3cbcbbef70a5fe0eb74268938e26f1bfe6 Mon Sep 17 00:00:00 2001 From: Azriel Hoh Date: Tue, 13 Oct 2020 19:30:16 +1300 Subject: [PATCH] Update `README.md` to be more concise. --- README.md | 41 ++++++++++++++++------------------------- src/lib.rs | 41 +++++++++++++++++------------------------ 2 files changed, 33 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 00282da..f934981 100644 --- a/README.md +++ b/README.md @@ -8,35 +8,26 @@ Returns type names with a specifiable number of module segments as a `String`. ```rust -// === std library === // -assert_eq!( - std::any::type_name::>(), - "core::option::Option", -); - -// === tynm === // -// Simple type name: -assert_eq!(tynm::type_name::>(), "Option",); - -// Type name with 1 module segment, starting from the most significant module. -assert_eq!( - tynm::type_namem::>(1), - "core::..::Option", -); - -// Type name with 1 module segment, starting from the least significant module. +#[rustfmt::skip] assert_eq!( - tynm::type_namen::>(1), - "..::option::Option<..::string::String>", + std::any::type_name::>(), "core::option::Option" ); -// Type name with 1 module segment from both the most and least significant modules. #[rustfmt::skip] -mod rust_out { pub mod two { pub mod three { pub struct Struct; } } } -assert_eq!( - tynm::type_namemn::(1, 1), - "rust_out::..::three::Struct", -); +let tuples = vec![ + (tynm::type_name::>(), "Option"), + (tynm::type_namem::>(1), "core::..::Option"), + (tynm::type_namen::>(1), "..::option::Option<..::string::String>"), + // 1 segment from most and least significant modules. + (tynm::type_namemn::(1, 1), "rust_out::..::three::Struct"), + // traits + (tynm::type_name::(), "dyn Debug"), +]; + +tuples + .iter() + .for_each(|(left, right)| assert_eq!(left, right)); + ``` ## Motivation diff --git a/src/lib.rs b/src/lib.rs index 7f6627c..f9be721 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,35 +3,28 @@ //! Returns type names with a specifiable number of module segments as a `String`. //! //! ```rust -//! // === std library === // +//! #[rustfmt::skip] //! assert_eq!( -//! std::any::type_name::>(), -//! "core::option::Option", +//! std::any::type_name::>(), "core::option::Option" //! ); //! -//! // === tynm === // -//! // Simple type name: -//! assert_eq!(tynm::type_name::>(), "Option",); -//! -//! // Type name with 1 module segment, starting from the most significant module. -//! assert_eq!( -//! tynm::type_namem::>(1), -//! "core::..::Option", -//! ); +//! #[rustfmt::skip] +//! let tuples = vec![ +//! (tynm::type_name::>(), "Option"), +//! (tynm::type_namem::>(1), "core::..::Option"), +//! (tynm::type_namen::>(1), "..::option::Option<..::string::String>"), +//! // 1 segment from most and least significant modules. +//! (tynm::type_namemn::(1, 1), "rust_out::..::three::Struct"), +//! // traits +//! (tynm::type_name::(), "dyn Debug"), +//! ]; //! -//! // Type name with 1 module segment, starting from the least significant module. -//! assert_eq!( -//! tynm::type_namen::>(1), -//! "..::option::Option<..::string::String>", -//! ); +//! tuples +//! .iter() +//! .for_each(|(left, right)| assert_eq!(left, right)); //! -//! // Type name with 1 module segment from both the most and least significant modules. -//! #[rustfmt::skip] -//! mod rust_out { pub mod two { pub mod three { pub struct Struct; } } } -//! assert_eq!( -//! tynm::type_namemn::(1, 1), -//! "rust_out::..::three::Struct", -//! ); +//! # #[rustfmt::skip] +//! # mod rust_out { pub mod two { pub mod three { pub struct Struct; } } } //! ``` //! //! # Motivation