pub enum TypeName<'s> {
None,
Array(TypeNameArray<'s>),
Never,
Pointer(TypeNamePointer<'s>),
Reference(TypeNameReference<'s>),
Slice(TypeNameSlice<'s>),
Struct(TypeNameStruct<'s>),
Tuple(TypeNameTuple<'s>),
Trait(TypeNameTrait<'s>),
Unit,
}
Expand description
Organizes type name string into distinct parts.
Variants
None
Array(TypeNameArray<'s>)
Never
Pointer(TypeNamePointer<'s>)
Reference(TypeNameReference<'s>)
Slice(TypeNameSlice<'s>)
Struct(TypeNameStruct<'s>)
Tuple(TypeNameTuple<'s>)
Trait(TypeNameTrait<'s>)
Unit
Implementations
sourceimpl<'s> TypeName<'s>
impl<'s> TypeName<'s>
sourcepub fn new<T: ?Sized>() -> Self
pub fn new<T: ?Sized>() -> Self
Constructs a new TypeName with the name of T
.
This is equivalent to calling std::any::type_name::<T>().into()
sourcepub fn as_str(&self) -> String
pub fn as_str(&self) -> String
Returns the type name string without any module paths.
This is equivalent to calling TypeName::as_str_mn(0, 0);
sourcepub fn as_str_mn(&self, m: usize, n: usize) -> String
pub fn as_str_mn(&self, m: usize, n: usize) -> String
Returns the type name string with the given number of module segments.
If the left and right module segments overlap, the overlapping segments will only be printed printed once.
Parameters
m
: Number of module segments to include, beginning from the left (most significant).n
: Number of module segments to include, beginning from the right (least significant).
sourcepub fn as_display(&self) -> TypeNameDisplay<'_>
pub fn as_display(&self) -> TypeNameDisplay<'_>
Returns an object that implements fmt::Display
for printing the type
name without any module paths directly with format!
and {}
.
When using this type name in a format!
or similar it is more efficient
to use this display instead of first creating a string.
Example
use tynm::TypeName;
let tn = TypeName::new::<String>();
println!("{}", tn.as_display());
sourcepub fn as_display_mn(&self, m: usize, n: usize) -> TypeNameDisplay<'_>
pub fn as_display_mn(&self, m: usize, n: usize) -> TypeNameDisplay<'_>
Returns an object that implements fmt::Display
for printing the type
name without any module paths directly with format!
and {}
.
When using this type name in a format!
or similar it is more efficient
to use this display instead of first creating a string.
If the left and right module segments overlap, the overlapping segments will only be printed once.
Parameters
buffer
: Buffer to write to.m
: Number of module segments to include, beginning from the left (most significant).n
: Number of module segments to include, beginning from the right (least significant).
Example
use tynm::TypeName;
let tn = TypeName::new::<String>();
println!("{}", tn.as_display_mn(1, 2));
sourcepub fn write_str<W>(&self, buffer: &mut W, m: usize, n: usize) -> Result<(), Error> where
W: Write,
pub fn write_str<W>(&self, buffer: &mut W, m: usize, n: usize) -> Result<(), Error> where
W: Write,
Writes the type name string to the given buffer.
If the left and right module segments overlap, the overlapping segments will only be printed once.
Parameters
buffer
: Buffer to write to.m
: Number of module segments to include, beginning from the left (most significant).n
: Number of module segments to include, beginning from the right (least significant).
Trait Implementations
impl<'s> Eq for TypeName<'s>
impl<'s> StructuralEq for TypeName<'s>
impl<'s> StructuralPartialEq for TypeName<'s>
Auto Trait Implementations
impl<'s> RefUnwindSafe for TypeName<'s>
impl<'s> Send for TypeName<'s>
impl<'s> Sync for TypeName<'s>
impl<'s> Unpin for TypeName<'s>
impl<'s> UnwindSafe for TypeName<'s>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more