Zero copy string array deserialization #1035
Unanswered
marcoradocchia
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I suspect this is #490, see #490 (comment) |
Beta Was this translation helpful? Give feedback.
1 reply
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'm failing to deserialize a TOML array of strings in a zero-copy fashion. I have implemented
Deserialize
on my custom type, along with its respectiveVisitor
. In the visitor'svisit_seq
method override I would like to match onseq.next_element::<&str>()
without aString
allocation, since I don't need to keep it, but rather increment a counter depending on its value and drop it. Sadly, this results in the following error:invalid type: string "...", expected a borrowed string
.Is my approach correct? Am I missing some knowledge? Or is this to be considered a bug?
Example
Output
Executing the above example produces the following output:
Opting for owned
String
s works as expected, at the cost of an allocation per value:Please note that the illustrated example is not my actual use-case, but rather a minimal gist able to reproduce the issue.
Beta Was this translation helpful? Give feedback.
All reactions