Crates.io | tynm |
lib.rs | tynm |
version | 0.1.10 |
source | src |
created_at | 2019-12-29 22:21:27.797782 |
updated_at | 2024-02-12 06:58:04.018591 |
description | Returns type names in shorter form. |
homepage | |
repository | https://github.com/azriel91/tynm |
max_upload_size | |
id | 193347 |
size | 79,633 |
Returns type names with a specifiable number of module segments as a String
.
Add the following to Cargo.toml
tynm = "0.1.10"
In code:
#[rustfmt::skip]
assert_eq!(
core::any::type_name::<Option<String>>(), "core::option::Option<alloc::string::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"),
];
tuples
.iter()
.for_each(|(left, right)| assert_eq!(left, right));
The core::any::type_name
function stabilized in Rust 1.38 returns the fully qualified type
name with all module segments. This can be difficult to read in error messages, especially for
type-parameterized types.
Often, the simple type name is more readable, and enough to distinguish the type referenced in an error.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.