Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add recoverable errors #30

Merged
merged 10 commits into from
Jan 11, 2024
Merged

Add recoverable errors #30

merged 10 commits into from
Jan 11, 2024

Conversation

malik672
Copy link
Owner

fix issue #26
bump to 0.9.0
introduce recoverable errors

@malik672 malik672 requested a review from shuhuiluo January 10, 2024 20:11
Copy link
Collaborator

@shuhuiluo shuhuiluo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will review later.

.DS_Store Outdated Show resolved Hide resolved
src/.DS_Store Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to git rm --cached .DS_Store since it's already added to git indexing.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

src/entities/fractions/fraction.rs Outdated Show resolved Hide resolved
assert!(Fraction::new(5, 12) > Fraction::new(4, 12));
}

#[test]
fn test_multiply() {
assert_eq!(
Fraction::new(1, 10) * Fraction::new(4, 12),
(Fraction::new(1, 10) * Fraction::new(4, 12)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding redundant parenthesis only increases the cost to review.

Comment on lines 348 to 349
assert_eq!(f.clone().as_fraction(), f.clone());
assert_ne!(&f.clone() as *const _, &f.clone().as_fraction() as *const _);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to make clones if the code was working as intended.

Comment on lines 25 to 27
(self.as_fraction() * ONE_HUNDRED.clone())
.to_significant(significant_digits, rounding)
.unwrap()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base method returns Result<String, Error>. Why is it unwrapped here?

}

/// Converts the Percent to a string with a fixed number of decimal places and rounding strategy
pub fn to_fixed(&self, decimal_places: u8, rounding: Rounding) -> String {
// Convert the Percent to a simple Fraction, multiply by 100, and then call to_fixed on the result
// Convert the Percent to a simple Fraction, multiply by 100, and then call to_fixed on the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Convert the Percent to a simple Fraction, multiply by 100, and then call to_fixed on the
// Convert the Percent to a simple Fraction, multiply by 100, and then call to_fixed on the result

Please don't accidentally delete comments.

@@ -39,47 +41,47 @@ mod tests {
#[test]
fn test_add() {
assert_eq!(
Percent::new(1, 100) + Percent::new(2, 100),
(Percent::new(1, 100) + Percent::new(2, 100)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just unnecessary diffs.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way clippy can discover this

return Err(Error::NotEqual("the comparison are not equal".to_owned()));
}

let fraction = (self.as_fraction() * other.as_fraction()).clone();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A clone is unnecessary.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

src/entities/fractions/price.rs Show resolved Hide resolved
@malik672 malik672 closed this Jan 11, 2024
@malik672 malik672 reopened this Jan 11, 2024
@malik672 malik672 merged commit 034cd2a into master Jan 11, 2024
4 checks passed
@malik672 malik672 deleted the add_recoverable_errors branch January 11, 2024 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants