Module tap::conv

source ·
Expand description

Method-Directed Type Conversion

The std::convert module provides traits for converting values from one type to another. The first of these, From<T>, provides an associated function from(orig: T) -> Self. This function can only be called in prefix-position, as it does not have a self receiver. The second, Into<T>, provides a method into(self) -> T which can be called in suffix-position; due to intractable problems in the type solver, this method cannot have any further method calls attached to it. It must be bound directly into a let or function call.

The TryFrom<T> and TryInto<T> traits have the same properties, but permit failure.

This module provides traits that place the conversion type parameter in the method, rather than in the trait, so that users can write .conv::<T>() to convert the preceding expression into T, without causing any failures in the type solver. These traits are blanket-implemented on all types that have an Into<T> implementation, which covers both the blanket implementation of Into for types with From, and manual implementations of Into.

!

Traits

  • Wraps Into::<T>::into as a method that can be placed in pipelines.
  • Wraps TryInto::<T>::try_into as a method that can be placed in pipelines.