Example in documentation about rust SDK to use Cow<'static, str> seems to be misleading. #5808
CodeServant
started this conversation in
Documentation
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I tried to understand why I should use
Cow<'static, str>
instead of String as in the example in documentation. I came to the conclusion that the example is misleading besause it says thatSo comment says that i should do it to
avoid unnecesary allocation while inserting
. In some cases serde optimizes with just borrowing the &str. But the problem is that, with the provided example, it only does that for hardcoded string literals. I found explaination here forCow<'static, str>
that it is basically replacement for&str
.This example works because there is hardcoded literal. But to actually be practical should look like this which is impossible with
static
.So the example should look like this.
So here is my question. Is the documentation right? Mayby I am missing something.
Beta Was this translation helpful? Give feedback.
All reactions