Stream: general

Topic: Derive clone on a generic


Martin Asquino (Apr 05 2020 at 10:34, on Zulip):

Hi! I'm having a difficult time understanding why this works: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=324b11e7212a1932c79d3a43c58f796e
but this doesn't: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=65c5f7564fd56aa8ba2f93e6c7637517

What am I missing here? :thinking:

Martin Asquino (Apr 05 2020 at 10:59, on Zulip):

Also, manually implementing clone works alright https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=65c5f7564fd56aa8ba2f93e6c7637517

detrumi (Apr 05 2020 at 11:00, on Zulip):

I think it's because Arc only implements Clone for Sized types, and the second Client type is generic over any type. And I don't think #[derive(Clone) works here, even if you use Sized bounds in the struct

detrumi (Apr 05 2020 at 11:00, on Zulip):

Martin Asquino said:

Also, manually implementing clone works alright https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=65c5f7564fd56aa8ba2f93e6c7637517

Same link as second example

Martin Asquino (Apr 05 2020 at 11:09, on Zulip):

Oh, my bad, here goes: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=d3f88d0d7f91ac0a1c69a6a395c537ad

Martin Asquino (Apr 05 2020 at 11:11, on Zulip):

makes sense, but I guess I don't understand why setting the Sized constraint on the generic types doesn't do the trick now

detrumi (Apr 05 2020 at 11:20, on Zulip):

Look's like it's a known problem, but hard to fix: https://github.com/rust-lang/rust/issues/26925

Martin Asquino (Apr 05 2020 at 11:30, on Zulip):

oh nice find! I think I kinda understand now :grinning:

Martin Asquino (Apr 05 2020 at 11:30, on Zulip):

thank you!

Last update: May 29 2020 at 15:55UTC