Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl Encode / Decode / Type for Arc<str> #1904

Open
domodwyer opened this issue Jun 14, 2022 · 1 comment · May be fixed by #3675
Open

impl Encode / Decode / Type for Arc<str> #1904

domodwyer opened this issue Jun 14, 2022 · 1 comment · May be fixed by #3675

Comments

@domodwyer
Copy link

The Encode, Decode and Type traits are already implemented for various types, including the clone-on-write Cow smart pointer - is there any objection to providing an impl for Arc<str> too?

Our use case is for storing/fetching new-type'd wrappers over ref-counted strings, such as:

pub struct PartitionKey(Arc<str>);

Where this type is wrote to / fetched from Postgres.

We Arc the underlying str to minimise memory usage (this particular string can have large ref counts). Currently we impl the encode / decode / type traits ourselves (as VARCHAR) and delegate serialisation to the existing str impls.

Ideally we'd like this to work:

#[derive(..., sqlx::Type)]
#[sqlx(transparent)]
pub struct PartitionKey(Arc<str>);

I'm happy to open a PR for this if it is desired 👍

@tylerhawkes
Copy link
Contributor

This should generally be implemented for all types T: Encode etc. Encode, Decode, and Type, should be implemented on the unsized types str and [T] and that would fix some of the problems I've run into lately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants