Trait TransitiveTryInto

Source
pub trait TransitiveTryInto<Error, Final>: Sized {
    // Provided method
    fn transitive_try_into<Transitive>(self) -> Result<Final, Error>
       where Self: TryInto<Transitive>,
             Transitive: TryInto<Final, Error = Error>,
             Error: From<Self::Error> { ... }
}
Expand description

A trait to perform a transitive try_into conversion.

This trait allows for a two-step conversion process where an initial type Self is first converted to an intermediate type Transitive, and then to the final type Final.

§Type Parameters

  • Error: The error type that can be produced during the conversion.
  • Final: The final type to which Transitive is converted.

§Requirements

  • Self must implement TryInto<Transitive>.
  • Transitive must implement TryInto<Final> with the same error type.
  • Error must implement From<<Self as TryInto<Transitive>>::Error>.

§Example

use pth::TransitiveTryInto;
use std::convert::TryInto;

struct InitialType;
struct IntermediateType;
struct FinalType;
struct ConversionError;

impl TryInto< IntermediateType > for InitialType
{
  type Error = ConversionError;
  fn try_into( self ) -> Result< IntermediateType, Self::Error >
  {
    // Conversion logic here
    Ok( IntermediateType )
  }
}

impl TryInto< FinalType > for IntermediateType
{
  type Error = ConversionError;
  fn try_into( self ) -> Result< FinalType, Self::Error >
  {
    // Conversion logic here
    Ok( FinalType )
  }
}

let initial = InitialType;
let final_result : Result< FinalType, ConversionError > = initial.transitive_try_into::< IntermediateType >();

Provided Methods§

Source

fn transitive_try_into<Transitive>(self) -> Result<Final, Error>
where Self: TryInto<Transitive>, Transitive: TryInto<Final, Error = Error>, Error: From<Self::Error>,

Performs a transitive try_into conversion.

This method first converts self to the intermediate type Transitive, and then converts the intermediate type to the final type Final.

§Returns
  • Ok(Final): If both conversions succeed.
  • Err(Error): If either conversion fails.
§Example

See the trait-level documentation for an example.

§Errors

qqq: doc

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<Error, Final, Initial> TransitiveTryInto<Error, Final> for Initial