pub trait TupleTryInto<T, E> {
// Required method
fn tuple_try_into(self) -> Result<T, E>;
}Expand description
A trait for fallibly converting a tuple into another tuple type.
This trait allows converting tuples into other tuple types where each element can be converted
using the standard TryFrom trait. The error type E must implement From for
each individual TryFrom error in the tuple, allowing error accumulation.
Part of the tuplities crate.
Required Methods§
Sourcefn tuple_try_into(self) -> Result<T, E>
fn tuple_try_into(self) -> Result<T, E>
Attempts to convert self into T.
§Errors
Returns an error of type E if any element conversion fails.
§Examples
use tuplities_try_from::TupleTryInto;
let source = (1u32, 2u32);
let target: Result<(u8, u8), _> = TupleTryInto::<(u8, u8), std::num::TryFromIntError>::tuple_try_into(source);
assert_eq!(target, Ok((1, 2)));
let invalid = (300u32, 2u32); // 300 is too big for u8
let result: Result<(u8, u8), _> = TupleTryInto::<(u8, u8), std::num::TryFromIntError>::tuple_try_into(invalid);
assert!(result.is_err());