Expose a trait to opt in for impl Type for PgRange<NewType>

Aperta
#4,411 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 4 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
postgresql, rust
Ambito
database

Direzione di ricerca

Start by reading the existing PgHasArrayType trait and the Type<Postgres> implementations for PgRange<T>; the issue does not name specific files or tests. Check how the current implementations represent range and array type information, including the concern about arrays of ranges. Done means newtype wrappers can opt in to PgRange<NewType> support without breaking existing implementations.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement
I have found these related issues/pull requests

It seems the same problem has been encountered before in #1258.

Description

My familiarity of SQLx is with Postgres exclusively, and hence my question uses that as frame of reference. The PgHasArrayType, which provides blanket impls like this has often been very useful to me:

impl<T> Type<Postgres> for Vec<T>
where
    T: PgHasArrayType,

On the other hand, since impl Type for PgRange<T> is done only for explicit types such as T = i64, there is no way for me to achieve impl Type for PgRange<NewType>, where NewType is a wrapper around i64 providing some invariant, but still being encoded as a BIGINT in Postgres.

I am using SQLx version 0.9.0.

Prefered solution

If this was also handled through a blanket impl

impl<T> Type<Postgres> for PgRange<T>
where
    T: PgHasRangeType,

where the proposed trait PgHasRangeType would provide everything the blanket impl needs, I could easily add my newtype to the mix.

I guess a nontrivial question would then also be how arrays of ranges are handled. The idea of a third trait such as PgRangeHasArrayType would be a bit out there, but on the other hand passing that information through PgHasRangeType would require some undesirable type system hacks, in my opinion. I really hope the inverse, a range of arrays, is not something anyone routinely needs.

Is this a breaking change? Why or why not?

No. The existing impl Type for PgRange<T> cases can be converted to impl PgHasRangeType for T, still indirectly providing the desired impl Type for PgRange<T>, or left as they are if desired.

Lingua principale
Rust
Stelle
17.5k
Fork
1.7k
Merge medio
1g 17h
PR unite (30g)
7

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di transact-rs/sqlx

Tutte le issue di transact-rs/sqlx

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.