1. 19

  2. 2

    Very informative article. I have a question about this though!

    + ?Sized - The size of B can be unknown at compile time. This isn’t relevant for our use case, but it means that trait objects may be used with the Cow type.

    But isn’t B a str which doesn’t have a size known at compile time?

    1. 2


      1. 2

        str doesn’t have a known size, but &str does: it’s the size of a (ptr, len) pair.

        1. 3

          Yes, but that’s &B. The statement quoted is that the “B: ?Sized” bound doesn’t matter for the thing described. It does, as B is str.

      2. 1

        I ran into this problem last weekend. This article provides a great walkthrough of the problem space.

        These days you can get the non-Cow solution by just setting your input as token: impl Into, which has nice ergonomics.

        I decided I’d prefer to have pretty code with the extra allocation rather than making API consumers worry about Cow’ing their inputs.