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§
source§impl<'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 core::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_opts(0, 0, TypeParamsFmtOpts::All);
sourcepub fn as_str_opts(&self, type_params_fmt_opts: TypeParamsFmtOpts) -> String
pub fn as_str_opts(&self, type_params_fmt_opts: TypeParamsFmtOpts) -> String
Returns the type name string without any module paths.
This is equivalent to calling TypeName::as_str_mn_opts(0, 0, type_params_fmt_opts);
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.
This is equivalent to calling TypeName::as_str_mn_opts(m, n, TypeParamsFmtOpts::All);
§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_str_mn_opts(
&self,
m: usize,
n: usize,
type_params_fmt_opts: TypeParamsFmtOpts
) -> String
pub fn as_str_mn_opts( &self, m: usize, n: usize, type_params_fmt_opts: TypeParamsFmtOpts ) -> 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).type_params_fmt_opts
: How to format type parameters, see the type documentation for details.
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_opts(
&self,
type_params_fmt_opts: TypeParamsFmtOpts
) -> TypeNameDisplay<'_>
pub fn as_display_opts( &self, type_params_fmt_opts: TypeParamsFmtOpts ) -> 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, TypeParamsFmtOpts};
let tn = TypeName::new::<String>();
println!("{}", tn.as_display_opts(TypeParamsFmtOpts::Std));
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 as_display_mn_opts(
&self,
m: usize,
n: usize,
type_params_fmt_opts: TypeParamsFmtOpts
) -> TypeNameDisplay<'_>
pub fn as_display_mn_opts( &self, m: usize, n: usize, type_params_fmt_opts: TypeParamsFmtOpts ) -> 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).type_params_fmt_opts
: How to format type parameters, see the type documentation for details.
§Example
use tynm::{TypeName, TypeParamsFmtOpts};
let tn = TypeName::new::<String>();
println!("{}", tn.as_display_mn_opts(1, 2, TypeParamsFmtOpts::Std));
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).
sourcepub fn write_str_opts<W>(
&self,
buffer: &mut W,
m: usize,
n: usize,
type_params_fmt_opts: TypeParamsFmtOpts
) -> Result<(), Error>where
W: Write,
pub fn write_str_opts<W>(
&self,
buffer: &mut W,
m: usize,
n: usize,
type_params_fmt_opts: TypeParamsFmtOpts
) -> 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).type_params_fmt_opts
: How to format type parameters, see the type documentation for details.