Skip to content

Commit

Permalink
Update README.md to be more concise.
Browse files Browse the repository at this point in the history
  • Loading branch information
azriel91 committed Oct 13, 2020
1 parent 4bc9098 commit 3a2a6b3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 49 deletions.
41 changes: 16 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Option<String>>(),
"core::option::Option<alloc::string::String>",
);

// === tynm === //
// Simple type name:
assert_eq!(tynm::type_name::<Option<String>>(), "Option<String>",);

// Type name with 1 module segment, starting from the most significant module.
assert_eq!(
tynm::type_namem::<Option<String>>(1),
"core::..::Option<alloc::..::String>",
);

// Type name with 1 module segment, starting from the least significant module.
#[rustfmt::skip]
assert_eq!(
tynm::type_namen::<Option<String>>(1),
"..::option::Option<..::string::String>",
std::any::type_name::<Option<String>>(), "core::option::Option<alloc::string::String>"
);

// 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::<rust_out::two::three::Struct>(1, 1),
"rust_out::..::three::Struct",
);
let tuples = vec![
(tynm::type_name::<Option<String>>(), "Option<String>"),
(tynm::type_namem::<Option<String>>(1), "core::..::Option<alloc::..::String>"),
(tynm::type_namen::<Option<String>>(1), "..::option::Option<..::string::String>"),
// 1 segment from most and least significant modules.
(tynm::type_namemn::<rust_out::two::three::Struct>(1, 1), "rust_out::..::three::Struct"),
// traits
(tynm::type_name::<dyn core::fmt::Debug>(), "dyn Debug"),
];

tuples
.iter()
.for_each(|(left, right)| assert_eq!(left, right));

```

## Motivation
Expand Down
41 changes: 17 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Option<String>>(),
//! "core::option::Option<alloc::string::String>",
//! std::any::type_name::<Option<String>>(), "core::option::Option<alloc::string::String>"
//! );
//!
//! // === tynm === //
//! // Simple type name:
//! assert_eq!(tynm::type_name::<Option<String>>(), "Option<String>",);
//!
//! // Type name with 1 module segment, starting from the most significant module.
//! assert_eq!(
//! tynm::type_namem::<Option<String>>(1),
//! "core::..::Option<alloc::..::String>",
//! );
//! #[rustfmt::skip]
//! let tuples = vec![
//! (tynm::type_name::<Option<String>>(), "Option<String>"),
//! (tynm::type_namem::<Option<String>>(1), "core::..::Option<alloc::..::String>"),
//! (tynm::type_namen::<Option<String>>(1), "..::option::Option<..::string::String>"),
//! // 1 segment from most and least significant modules.
//! (tynm::type_namemn::<rust_out::two::three::Struct>(1, 1), "rust_out::..::three::Struct"),
//! // traits
//! (tynm::type_name::<dyn core::fmt::Debug>(), "dyn Debug"),
//! ];
//!
//! // Type name with 1 module segment, starting from the least significant module.
//! assert_eq!(
//! tynm::type_namen::<Option<String>>(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::<rust_out::two::three::Struct>(1, 1),
//! "rust_out::..::three::Struct",
//! );
//! # #[rustfmt::skip]
//! # mod rust_out { pub mod two { pub mod three { pub struct Struct; } } }
//! ```
//!
//! # Motivation
Expand Down

0 comments on commit 3a2a6b3

Please sign in to comment.