Stream: t-compiler/help

Topic: `Iterator::find`, where Self: Sized


Bastian Kauschke (Apr 07 2020 at 15:35, on Zulip):

Why is there a Self: Sized bound for Iterator::find? https://github.com/rust-lang/rust/blob/39b62533c7f9d0581a6ea9b9fc2cc51f21c3b5b0/src/libcore/iter/traits/iterator.rs#L2198-L2200

eddyb (Apr 07 2020 at 15:36, on Zulip):

it's how you opt out of that method being in the vtable

Bastian Kauschke (Apr 07 2020 at 15:36, on Zulip):

That's actually clever, wow :laughing:

eddyb (Apr 07 2020 at 15:36, on Zulip):

all methods that take self by value in traits like Iterator (which we want to allow people to use with dyn Iterator) have that

Bastian Kauschke (Apr 07 2020 at 15:37, on Zulip):

but find doesn't take self by value

eddyb (Apr 07 2020 at 15:37, on Zulip):

oh maybe it's generic

eddyb (Apr 07 2020 at 15:38, on Zulip):

okay yeah that's another thing that virtual methods can't do

eddyb (Apr 07 2020 at 15:38, on Zulip):

so "takes self by value or is more generic than the trait"

Last update: Sep 27 2020 at 14:45UTC