Allow (de)serialization of Cow<'_, T> values#1545
Merged
Lorak-mmk merged 1 commit intoscylladb:mainfrom Jan 20, 2026
Merged
Conversation
|
|
Lorak-mmk
requested changes
Jan 15, 2026
Collaborator
Lorak-mmk
left a comment
There was a problem hiding this comment.
Thanks! I left just a few minor comments.
Comment on lines
+1621
to
+1638
| impl<'frame, 'metadata, T: 'frame + ToOwned + ?Sized> DeserializeValue<'frame, 'metadata> | ||
| for Cow<'frame, T> | ||
| where | ||
| &'frame T: DeserializeValue<'frame, 'metadata>, | ||
| { | ||
| fn type_check(typ: &ColumnType) -> Result<(), TypeCheckError> { | ||
| <&T>::type_check(typ).map_err(typck_error_replace_rust_name::<Self>) | ||
| } | ||
|
|
||
| fn deserialize( | ||
| typ: &'metadata ColumnType<'metadata>, | ||
| v: Option<FrameSlice<'frame>>, | ||
| ) -> Result<Self, DeserializationError> { | ||
| <&T>::deserialize(typ, v) | ||
| .map(Cow::Borrowed) | ||
| .map_err(deser_error_replace_rust_name::<Self>) | ||
| } | ||
| } |
Collaborator
There was a problem hiding this comment.
It's unfortunate that Rust doesn't have lifetime specialization (yes, I know there are big soundness issues with it). It would be great to use the Owned variant when deserializing to Cow<'static, T>, but that's not possible (at least for now).
Collaborator
There was a problem hiding this comment.
In docs/source/data-types/data-types.md there is the following line:
Additionally, BoxandArc serialization and deserialization is supported for all above types.
Could you modify it to also mention Cow?
There is already precedence for doing this for Arc<T> and Box<T>
02efebe to
820f304
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There is already precedence for doing this for Arc and Box so this PR merely extends the same functionality to a another stdlib smart pointer.
In particular this is useful for me when doing a maybe borrowed deserialization in serde where the string may or may not need to be owned (depending on whether the string was escaped in the input). This maybe borrowed deserialization is done by storing it in a
Cow<'_, str>. I want to then store thatCow<'_, str>asTEXTin Scylla without too much work but prior to this PR that was not doable.While I personally only care about serializing
Cow<'_, str>I figured the driver should be more general and allow for any T and for both serialization and deserialization as it is done for Arc and Box. The main difference is that I didn't need to special case Cow as a generic implementation works just fine.Pre-review checklist
./docs/source/.Fixes:annotations to PR description.