Skip to content

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

Open
@domodwyer

Description

@domodwyer

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 👍

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions