ICU4X data structs don't actually borrow any data #632
Labels
C-data-infra
Component: provider, datagen, fallback, adapters
duplicate
This issue or pull request already exists
S-medium
Size: Less than a week (larger bug fix or enhancement)
T-bug
Type: Bad behavior, security, privacy
Milestone
I discovered that even though we religiously use
Cow<'s, str>
and similar in our data structs, we are not actually benefiting from zero-copy deserialization, because the default implementation ofDeserialize
forCow<'s, str>
is to always useOwned
data. See a discussion here: serde-rs/serde#1497We need our structs to support zero-copy deserialization. This requires adding
#[serde(borrow)]
to opt in where possible, keeping the following issues in mind: serde-rs/serde#2016, serde-rs/serde#723.Unfortunately, if we make this change, it means that we will no longer be able to read from an
std::io::Read
when deserializing. We must always load the buffer and then point into the buffer. This might be an okay constraint for ICU4X, but I want to make sure we are explicit about it.If we want to retain the ability to deserialize into a
'static
, we could add functions that flatten the lifetime on the data struct after we deserialize it from a borrowed buffer.CC @Manishearth
The text was updated successfully, but these errors were encountered: