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

Symmetry for Ratio::new_raw #115

Closed
zbrachinara opened this issue Mar 30, 2023 · 2 comments · Fixed by #129
Closed

Symmetry for Ratio::new_raw #115

zbrachinara opened this issue Mar 30, 2023 · 2 comments · Fixed by #129

Comments

@zbrachinara
Copy link

zbrachinara commented Mar 30, 2023

A request to create a function (for now I'll call it Ratio::into_raw) which acts like this:

fn into_raw(self) -> (T, T) {
	(self.numer, self.denom)
}

This would be useful as a way to circumvent unnecessary cloning while maintaining the "weak invariants" of Ratio (mentioned in this issue). It would also be useful for "manually" implementing more efficient primitive operations on BigRational from outside of num-rational like so:

fn div_by_u32(rational: BigRational, primitive: u32) -> Option<BigRational> {
	(primitive != 0).then(|| {
		let (numer, mut denom) = rational.into_raw();
		denom *= primitive;
		BigRational::new_raw(numer, denom)
	})
}

This could solve issues that #38 tries to solve without making as much of a sweeping change, which hopefully will help it to be accepted more quickly.

@zbrachinara
Copy link
Author

I misclicked the "create issue" button, so apologies for any errors in the code or being too terse

@cuviper
Copy link
Member

cuviper commented Mar 5, 2024

Sorry I missed this -- I think into_raw sounds like a fine addition.

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 a pull request may close this issue.

2 participants