fastnum/decimal/udec/impls/
cast.rs1use crate::{
2 decimal::{Decimal, ParseError, UnsignedDecimal},
3 utils::const_generics::{Dimension, Narrow, Widen},
4 Cast, TryCast,
5};
6
7type D<const N: usize> = Decimal<N>;
8type UD<const N: usize> = UnsignedDecimal<N>;
9
10impl<const N: usize, const M: usize> Cast<UD<N>> for UD<M>
11where
12 Dimension<N, M>: Widen,
13{
14 #[inline(always)]
15 fn cast(self) -> UD<N> {
16 UD::new(self.0.cast())
17 }
18}
19
20impl<const N: usize, const M: usize> TryCast<UD<N>> for UD<M>
21where
22 Dimension<N, M>: Narrow,
23{
24 type Error = ParseError;
25
26 #[inline(always)]
27 fn try_cast(self) -> Result<UD<N>, Self::Error> {
28 self.0.try_cast().map(UD::new)
29 }
30}
31
32impl<const N: usize, const M: usize> Cast<D<N>> for UD<M>
33where
34 Dimension<N, M>: Widen,
35{
36 #[inline(always)]
37 fn cast(self) -> D<N> {
38 self.0.cast()
39 }
40}
41
42impl<const N: usize> Cast<D<N>> for UD<N> {
43 #[inline(always)]
44 fn cast(self) -> D<N> {
45 self.0
46 }
47}
48
49impl<const N: usize, const M: usize> TryCast<D<N>> for UD<M>
50where
51 Dimension<N, M>: Narrow,
52{
53 type Error = ParseError;
54
55 #[inline(always)]
56 fn try_cast(self) -> Result<D<N>, Self::Error> {
57 self.0.try_cast()
58 }
59}