Skip to content

Commit

Permalink
Relax Sized bound on T.
Browse files Browse the repository at this point in the history
  • Loading branch information
azriel91 committed Oct 13, 2020
1 parent 8f40299 commit 1cccfa7
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ mod types;
/// ```rust
/// assert_eq!(tynm::type_name::<Option<String>>(), "Option<String>",);
/// ```
pub fn type_name<T>() -> String {
pub fn type_name<T>() -> String
where
T: ?Sized,
{
type_namemn::<T>(0, 0)
}

Expand All @@ -83,7 +86,10 @@ pub fn type_name<T>() -> String {
/// "core::..::Option<alloc::..::String>",
/// );
/// ```
pub fn type_namem<T>(m: usize) -> String {
pub fn type_namem<T>(m: usize) -> String
where
T: ?Sized,
{
type_namemn::<T>(m, 0)
}

Expand All @@ -105,7 +111,10 @@ pub fn type_namem<T>(m: usize) -> String {
/// "..::option::Option<..::string::String>",
/// );
/// ```
pub fn type_namen<T>(n: usize) -> String {
pub fn type_namen<T>(n: usize) -> String
where
T: ?Sized,
{
type_namemn::<T>(0, n)
}

Expand All @@ -128,7 +137,10 @@ pub fn type_namen<T>(n: usize) -> String {
/// "..::option::Option<..::string::String>",
/// );
/// ```
pub fn type_namemn<T>(m: usize, n: usize) -> String {
pub fn type_namemn<T>(m: usize, n: usize) -> String
where
T: ?Sized,
{
let type_name_qualified = std::any::type_name::<T>();

let type_name = TypeName::from(type_name_qualified);
Expand Down Expand Up @@ -230,4 +242,9 @@ mod tests {
"::usize"
);
}

#[test]
fn type_name_unsized() {
assert_eq!(type_name::<dyn std::fmt::Debug>(), "std::fmt::Debug");
}
}

0 comments on commit 1cccfa7

Please sign in to comment.