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 whichTransitiveis converted.
§Requirements
Selfmust implementTryInto<Transitive>.Transitivemust implementTryInto<Final>with the same error type.Errormust implementFrom<<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§
Sourcefn transitive_try_into<Transitive>(self) -> Result<Final, Error>
fn transitive_try_into<Transitive>(self) -> Result<Final, 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.