Skip to content

Symmetry for Ratio::new_raw #115

Closed
@zbrachinara

Description

@zbrachinara

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions