Stream: general

Topic: impl Array


pnkfelix (Apr 01 2019 at 14:20, on Zulip):

@oli , regarding your comment on rust-lang/rfcs#2545, what is the strategy there for allowing operations like deriving Debug or even indexing just into the Array? I tried playing with the code and found that attempting to add Deref or Index impls hit errors about "trait Array cannot be made into an object" due to its use of an associated const.

oli (Apr 01 2019 at 15:01, on Zulip):

Debug works out of the box by adding it as a bound to Array's definition, but unfortunately almost all other common operations are implemented indirectly via Unsize, so every use site would need &FOO as &[T], which makes my idea unactionable. We'd need some language/compiler magic that would make impl Unsize<T> also allow operations via the unsizing (and as a consequence, also allow U: Unsize<[T]> bounds on generic functions to allow indexing into values of type U. I wonder if we'd get these automatically by implementing Deref for all array types up to length 32.

pnkfelix (Apr 01 2019 at 15:19, on Zulip):

Hmm I thought I tried adding Debug as a bound and found it did not work

pnkfelix (Apr 01 2019 at 15:20, on Zulip):

can one make it a bound that is conditional on whether T: Debug ?

oli (Apr 02 2019 at 07:02, on Zulip):

Ah no, probably not.

pnkfelix (Apr 02 2019 at 09:20, on Zulip):

okay. so basically, the idea doesn't work on any front. :smile:

Last update: Nov 20 2019 at 11:25UTC