@@ -20,6 +20,7 @@ impl<M: Default> Default for FractionLike<M> {
20
20
}
21
21
}
22
22
23
+ /// Implement [`Deref`] to allow direct access to the metadata of the fraction
23
24
impl < M > Deref for FractionLike < M > {
24
25
type Target = M ;
25
26
@@ -38,7 +39,7 @@ impl Fraction {
38
39
}
39
40
}
40
41
41
- /// Function to convert the custom Rounding enum to `bigdecimal`'s `RoundingMode`
42
+ /// Function to convert the custom Rounding enum to [ `bigdecimal`] 's [ `RoundingMode`]
42
43
const fn to_rounding_strategy ( rounding : Rounding ) -> RoundingMode {
43
44
match rounding {
44
45
Rounding :: RoundDown => RoundingMode :: Down ,
@@ -92,12 +93,13 @@ pub trait FractionBase<M>: Sized {
92
93
Self :: new ( self . denominator ( ) , self . numerator ( ) , self . meta ( ) )
93
94
}
94
95
95
- /// Converts the fraction to a `bigdecimal:: BigDecimal`
96
+ /// Converts the fraction to a [` BigDecimal`]
96
97
fn to_decimal ( & self ) -> BigDecimal {
97
98
BigDecimal :: from ( self . numerator ( ) ) . div ( BigDecimal :: from ( self . denominator ( ) ) )
98
99
}
99
100
100
- /// Converts the fraction to a string with a specified number of significant digits and rounding strategy
101
+ /// Converts the fraction to a string with a specified number of significant digits and rounding
102
+ /// strategy
101
103
fn to_significant ( & self , significant_digits : u8 , rounding : Rounding ) -> Result < String , Error > {
102
104
if significant_digits == 0 {
103
105
return Err ( Error :: Incorrect ( ) ) ;
@@ -111,7 +113,8 @@ pub trait FractionBase<M>: Sized {
111
113
Ok ( quotient. normalized ( ) . to_string ( ) )
112
114
}
113
115
114
- /// Converts the fraction to a string with a fixed number of decimal places and rounding strategy
116
+ /// Converts the fraction to a string with a fixed number of decimal places and rounding
117
+ /// strategy
115
118
fn to_fixed ( & self , decimal_places : u8 , rounding : Rounding ) -> String {
116
119
let rounding_strategy = to_rounding_strategy ( rounding) ;
117
120
let quotient = self
@@ -121,17 +124,16 @@ pub trait FractionBase<M>: Sized {
121
124
format ! ( "{:.1$}" , quotient, decimal_places as usize )
122
125
}
123
126
124
- /// Helper method for converting any superclass back to a simple Fraction
127
+ /// Helper method for converting any superclass back to a simple [` Fraction`]
125
128
fn as_fraction ( & self ) -> Fraction {
126
129
Fraction :: new ( self . numerator ( ) , self . denominator ( ) )
127
130
}
128
131
}
129
132
130
- /// Implementation of the FractionTrait for FractionLike
131
133
impl < M : Clone + PartialEq > FractionTrait < M > for FractionLike < M > { }
132
134
133
135
impl < M : Clone > FractionBase < M > for FractionLike < M > {
134
- /// Constructor for creating a new Fraction with metadata
136
+ /// Constructor for creating a new [`FractionLike`] with metadata
135
137
fn new ( numerator : impl Into < BigInt > , denominator : impl Into < BigInt > , meta : M ) -> Self {
136
138
let denominator = denominator. into ( ) ;
137
139
// Ensure the denominator is not zero
@@ -239,7 +241,6 @@ impl<M: Clone> Mul for FractionLike<M> {
239
241
240
242
/// Multiplies the current fraction by another fraction
241
243
fn mul ( self , other : Self ) -> Self :: Output {
242
- //There's little to no possibility of an error, so unwrap can be used
243
244
FractionBase :: new (
244
245
self . numerator ( ) * other. numerator ( ) ,
245
246
self . denominator ( ) * other. denominator ( ) ,
0 commit comments