impl From<&Big[U]Int> for Big[U]Int#204
Open
coolreader18 wants to merge 1 commit intorust-num:masterfrom
Open
Conversation
40c32a8 to
50d5af6
Compare
Member
|
What's the reason you can't use |
Author
|
Yeah, if I pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
VecorStringhave aFrom<&slicetype>impl (whereslicetypeis[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 Foolike standard library types do.Alternatively, I guess there could be a
IntoBigInttrait in addition to theToBigIntone.