Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upability to opt out of auto-rolling of reflexive From #42861
Comments
This comment has been minimized.
This comment has been minimized.
|
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. |
Mark-Simulacrum
closed this
Jun 23, 2017
This comment has been minimized.
This comment has been minimized.
|
Does the |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
hmmm , so it has been considered and found to be problematic ... are those problems 'permanent',or just potential opinions (e.g. library generality) |
This comment has been minimized.
This comment has been minimized.
|
Accessing from some structure by type "name" can be done with https://docs.rs/typemap/. I can't find anything on |
This comment has been minimized.
This comment has been minimized.
|
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 |
dobkeratops commentedJun 23, 2017
•
edited
In order to facilitate impl'ing
Fromfor 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
NotReflexiveFromhelper-trait which whenimpld 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!=BI 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)