-
Notifications
You must be signed in to change notification settings - Fork 13k
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
ability to opt out of auto-rolling of reflexive From #42861
Comments
I think what you really want is specialization, which is currently primarily waiting on Chalk; opting out of impls isn't quite what you want -- rather, you want to specialize core's impl for your types. As such, I'm going to go ahead and close -- see #31844 and rust-lang/rust-roadmap-2017#8. |
Does the |
A != B introduces problems IIRC; I don't recall what they are though. Feel free to ask on internals.rust-lang.org or users.rust-lang.org, though. |
I'd guess the big problem is either contexts where you don't know yet if two type parameters are equal or unequal, or cases where you can't know if they will always stay equal/unequal after the library adds new impls or the app adds new call sites. But an A!=B bound on an impl should always be equivalent to adding a specializing impl for the A==B case (unless you don't want an impl to exist at all if A==B, which afaik is not something anyone ever wants), so I'd just focus on specialization. |
hmmm , so it has been considered and found to be problematic ... are those problems 'permanent',or just potential opinions (e.g. library generality) |
Accessing from some structure by type "name" can be done with https://docs.rs/typemap/. I can't find anything on |
type map looks interesting, thanks , (i'm not sure i understand fully.. i'll have to check what UnsafeAny does) - but it's far more general than the case I had in mind which would be implementing a |
In order to facilitate impl'ing
From
for collections/wrapped types, would it be possible to amend the library (within the existing language features) to allow the user to opt out of 'core's' generation of reflexiveT:From<T>
this was my scenario,
https://www.reddit.com/r/rust/comments/6ieagx/from_generic_impl_conflict_vector_maths/
To summarise
impl From<Vec3<B>> for Vec3<A> where A:From<B>
seemed to clash with core's reflexive impl of 'From' (i.e. From<Vec3> for Vec2my workaround was to manually impl for specific types but this is messy,
Do the "negative trait bounds" offer a solution? - e.g. could there be a
NotReflexiveFrom
helper-trait which whenimpl
d for a type (in my case,Vec3<T>
) would suppress the library reflexive-from.The reverse - an opt-in sounds easier r.e. the existing language features, but that would be a breaking library change, right?
I think the clearest solution to my situation would be a not equal type-bound e.g.
where A!=B
?impl From<Vec3<B>> for Vec3<A> where A:From<B>, A!=B
I tried to hack a manual
A:IsNot<B>
but once again I seemed to need to roll this for specific types so I was back to square one.https://users.rust-lang.org/t/not-equal-type-bound-e-g-where-t-y/11442
Could an automatic
A:IsNot<B>
be done through a "procedural macro" ?For reference, equivalent C++ situation - the behaviour I'm trying to get close to in Rust
Here is is possible using 'conversion operators' or constructors, because a type can respond to casting to itself automatically already, and you can go ahead and write a templated conversion.
I am ok with the fact rust conversions are 'explicit' by default ('write .into()' giving a clear point where conversions occur), but I still want to be able to request conversions between anything that makes sense (in this example, many possible formats of vector data)
The text was updated successfully, but these errors were encountered: