use crate::{
numeric::{Cast, CastError, LossyCast, SaturatingCast, TryCast, TryExactCast},
tuple::Tuple,
};
impl<T, const N: usize> Tuple<T, N> {
#[inline]
pub fn cast<U>(self) -> Tuple<U, N>
where
T: Cast<U>,
{
self.map(|x| x.cast())
}
}
impl<T, U, const N: usize> Cast<Tuple<U, N>> for Tuple<T, N>
where
T: Cast<U>,
{
#[inline]
fn cast(self) -> Tuple<U, N> {
Tuple::cast(self)
}
}
impl<T, const N: usize> Tuple<T, N> {
#[inline]
pub fn cast_from<U>(value: Tuple<U, N>) -> Self
where
U: Cast<T>,
{
value.cast::<T>()
}
}
impl<T, const N: usize> Tuple<T, N> {
#[inline]
pub fn lossy_cast<U>(self) -> Tuple<U, N>
where
T: LossyCast<U>,
{
self.map(|x| x.lossy_cast())
}
}
impl<T, U, const N: usize> LossyCast<Tuple<U, N>> for Tuple<T, N>
where
T: LossyCast<U>,
{
#[inline]
fn lossy_cast(self) -> Tuple<U, N> {
Tuple::lossy_cast(self)
}
}
impl<T, const N: usize> Tuple<T, N> {
#[inline]
pub fn lossy_cast_from<U>(value: Tuple<U, N>) -> Self
where
U: LossyCast<T>,
{
value.lossy_cast::<T>()
}
}
impl<T, const N: usize> Tuple<T, N> {
#[inline]
pub fn saturating_cast<U>(self) -> Tuple<U, N>
where
T: SaturatingCast<U>,
{
self.map(|x| x.saturating_cast())
}
}
impl<T, U, const N: usize> SaturatingCast<Tuple<U, N>> for Tuple<T, N>
where
T: SaturatingCast<U>,
{
#[inline]
fn saturating_cast(self) -> Tuple<U, N> {
Tuple::saturating_cast(self)
}
}
impl<T, const N: usize> Tuple<T, N> {
#[inline]
pub fn saturating_cast_from<U>(value: Tuple<U, N>) -> Self
where
U: SaturatingCast<T>,
{
value.saturating_cast::<T>()
}
}
impl<T, const N: usize> Tuple<T, N> {
#[inline]
pub fn try_cast<U>(self) -> Result<Tuple<U, N>, CastError>
where
T: TryCast<U>,
{
self.try_map(|x| x.try_cast())
}
}
impl<T, U, const N: usize> TryCast<Tuple<U, N>> for Tuple<T, N>
where
T: TryCast<U>,
{
#[inline]
fn try_cast(self) -> Result<Tuple<U, N>, CastError> {
Tuple::try_cast(self)
}
}
impl<T, const N: usize> Tuple<T, N> {
#[inline]
pub fn try_cast_from<U>(value: Tuple<U, N>) -> Result<Self, CastError>
where
U: TryCast<T>,
{
value.try_cast::<T>()
}
}
impl<T, const N: usize> Tuple<T, N> {
#[inline]
pub fn try_exact_cast<U>(self) -> Result<Tuple<U, N>, CastError>
where
T: TryExactCast<U>,
{
self.try_map(|x| x.try_exact_cast())
}
}
impl<T, U, const N: usize> TryExactCast<Tuple<U, N>> for Tuple<T, N>
where
T: TryExactCast<U>,
{
#[inline]
fn try_exact_cast(self) -> Result<Tuple<U, N>, CastError> {
Tuple::try_exact_cast(self)
}
}
impl<T, const N: usize> Tuple<T, N> {
#[inline]
pub fn try_exact_cast_from<U>(value: Tuple<U, N>) -> Result<Self, CastError>
where
U: TryExactCast<T>,
{
value.try_exact_cast::<T>()
}
}