impl From<&Big[U]Int> for Big[U]Int #204
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I know this impl is a little strange, but I have a use case and a rationale.
So, I have a function that takes any
T: Into<BigInt> + ToPrimitive
. It converts the operand to an i32 and checks whether it's in some low range, and if it is, it can do an optimized version with the i32. Otherwise, it converts the operand to a BigInt and uses that. Currently, we have 2 versions of the function, one taking that generic and the other taking a&BigInt
, since it wouldn't have to clone the BigInt unless it's not in the low range. I could probably just make my own trait, but due to orphan rules I wouldn't be able to do the blanket impl, so it'd just be a bunch of manual impls. If this were implemented, I'd be able to have just the one function, and it would get the optimization for free.Also, the standard library containers like
Vec
orString
have aFrom<&slicetype>
impl (whereslicetype
is[T]
orstr
), but since BigInt doesn't deref to anything and you pass it by reference just as&BigInt
, I think it makes sense in general to have a implFrom<BorrowedFoo<'a>> for Foo
like standard library types do.Alternatively, I guess there could be a
IntoBigInt
trait in addition to theToBigInt
one.