sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

impl Encode / Decode / Type for Arc<str>

Open domodwyer opened this issue 3 years ago • 0 comments

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 :+1:

domodwyer avatar Jun 14 '22 14:06 domodwyer