Enum tynm::TypeName

source ·
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>

source

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()

source

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);

source

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);

source

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).
source

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.
source

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());
source

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));
source

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));
source

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));
source

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).
source

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.

Trait Implementations§

source§

impl<'s> Clone for TypeName<'s>

source§

fn clone(&self) -> TypeName<'s>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'s> Debug for TypeName<'s>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'s> From<&'s str> for TypeName<'s>

source§

fn from(std_type_name: &'s str) -> Self

Converts to this type from the input type.
source§

impl<'s> PartialEq for TypeName<'s>

source§

fn eq(&self, other: &TypeName<'s>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'s> Eq for TypeName<'s>

source§

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.