Skip to main content

PgCollectionStorage

Trait PgCollectionStorage 

Source
pub trait PgCollectionStorage<VF> {
    type Sequence: ComplexComparison<Postgres>;
    type Set: ComplexComparison<Postgres>;
}
Available on crate features postgres and sqlx only.
Expand description

Which storage strategy Postgres keeps a collection of THIS element type in — the half of CollectionStorage that the one dialect with two usable strategies cannot answer from the dialect alone.

Public, and for the reason Carrier is: this is the surface a downstream element type joins the collection vocabulary through on Postgres, and a type with a row here needs nothing else from this crate to be filtered on as a list or as a set.

§Why the dialect cannot answer alone

Both column-stored kinds’ Postgres lowerings are bounded V: PgHasArrayType — the sqlx row naming the array type OID an element lives in — and a great many element types have no such row. This crate’s own BeU64 is one: it binds fine as a scalar and sqlx names no array type for a blob carrier. A dialect-keyed answer sends every one of them to a column-stored kind and the bound then fails at the LOWERING, naming a sqlx trait, with no fallback and no way to ask for one.

So the refusal moves here, and moving it is half of what this trait buys: a missing row is E0277 at the crossing, naming the row a reader can go and write, where it used to be E0599 on apply naming PgHasArrayType. That message is pinned as exact text — tests/pg_collection_strategy/ — because it is the deliverable rather than a side effect.

§Why the choice is declared rather than deduced

The two impls that would deduce it —

impl<V: PgHasArrayType> CollectionStorage<V> for Postgres { … }
impl<V>                 CollectionStorage<V> for Postgres { … }

— are E0119, and both routes out of that are unstable: V: !PgHasArrayType is a negative bound and the alternative is specialization. So the choice is a ROW, and the row is keyed on the element type because that is what it is a fact about.

A blanket impl<V: PgHasArrayType> PgCollectionStorage for V is refused for the same reason one level down: it would make the array case automatic and then leave a type WITHOUT an array type unable to be given a row at all, since a specific impl would overlap the blanket and rustc will not prove the negative for a foreign trait. That closes the surface this trait exists to open. Per-type rows are what Carrier already asks for, and a downstream pays the same one-line price here that it pays there.

The strategy is not a fallback for types the array cannot hold. An element type with a perfectly good PgHasArrayType may name the edge table anyway — a list long enough that an unindexed @> over it is the wrong plan, or an index shape an array cannot give — and it costs one row. That was unspellable while the dialect answered.

§The two answers are independent, which the shape parameter could not make them

A row states its sequence strategy and its set strategy separately, so an element may keep an ordered column in an array and send its unordered one to an edge table — where an index on (key…, value) answers containment with a seek and an array cannot. Every row this crate ships states the same strategy twice, and that is a fact about these elements rather than a rule.

§The rows this crate ships

One per element type in the Postgres Carrier table, and the rule that picks between the two is a single question: does sqlx’s array type for this element match the column its carrier row binds into? Where it does, the array; where it does not — or where there is no array type at all — the edge table. See the two lists beside the rows themselves.

§The lowering promise travels ONE level further, for the reason it reached

CollectionStorage at all

Postgres’s row states whatever this one states — its two answers ARE this one’s — so a promise that stopped at the dialect would have to be proved from V: PgCollectionStorage alone, where the types are opaque. Restating it here is what makes it provable, and it lands where the choice is actually made: an element type picking a strategy is picking a comparison, and a strategy whose comparison cannot be lowered is not one.

§VF travels here too, for the reason it reached CollectionStorage

A strategy names a comparison and a collection comparison holds the ELEMENT’s, so a row states its answer over both. A row is still one line per element type, and it is where the element’s own crossing is finally written — at a named dialect, which is the only place a projection through it resolves.

§The refusal is WRITTEN, and the list beside it is made to stop moving

Unimplemented, rustc names the eight types with a row that sort first and says and N others. Which eight was a function of the FEATURE SET — the wrapper’s rows are jiff + time, so their presence displaced another entry — and the fixture that pins this refusal as exact text was therefore unassertable in any build without both, which is what kept a dialect-only build red. The wrapper’s two rows carry do_not_recommend and no other row does: they were the only entries that could come and go, so suppressing exactly them settles the text and leaves the list itself — which is a real suggestion to whoever reads it.

The sentence above is what a reader acts on, and it is written rather than inferred from that list, which names types and not the thing to do. The second note is there because this bound has a second way to fail that the first does not describe: Self may HAVE a row while {VF} has no ToDatabaseComparison into it. Which message a reader sees then depends on what they wrote — a failing PROJECTION is reported at that crossing directly and never reaches this text, while a caller who named this bound in a where-clause gets this one, and there the note is the only thing distinguishing the two missing pieces.

Required Associated Types§

Source

type Sequence: ComplexComparison<Postgres>

The comparison a ListFilter over a sequence of Self crosses into on Postgres.

Source

type Set: ComplexComparison<Postgres>

The comparison a SetFilter over a set of Self crosses into on Postgres.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<'a, VF: ToDatabaseComparison<&'a Date, Postgres>> PgCollectionStorage<VF> for &'a Date

Source§

impl<'a, VF: ToDatabaseComparison<&'a Duration, Postgres>> PgCollectionStorage<VF> for &'a Duration

Source§

impl<'a, VF: ToDatabaseComparison<&'a OffsetDateTime, Postgres>> PgCollectionStorage<VF> for &'a OffsetDateTime

Source§

impl<'a, VF: ToDatabaseComparison<&'a PgInterval, Postgres>> PgCollectionStorage<VF> for &'a PgInterval

Source§

impl<'a, VF: ToDatabaseComparison<&'a PrimitiveDateTime, Postgres>> PgCollectionStorage<VF> for &'a PrimitiveDateTime

Source§

impl<'a, VF: ToDatabaseComparison<&'a String, Postgres>> PgCollectionStorage<VF> for &'a String

Source§

impl<'a, VF: ToDatabaseComparison<&'a Time, Postgres>> PgCollectionStorage<VF> for &'a Time

Source§

impl<'a, VF: ToDatabaseComparison<&'a Vec<u8>, Postgres>> PgCollectionStorage<VF> for &'a Vec<u8>

Source§

impl<'a, VF: ToDatabaseComparison<&'a bool, Postgres>> PgCollectionStorage<VF> for &'a bool

Source§

impl<'a, VF: ToDatabaseComparison<&'a f32, Postgres>> PgCollectionStorage<VF> for &'a f32

Source§

impl<'a, VF: ToDatabaseComparison<&'a f64, Postgres>> PgCollectionStorage<VF> for &'a f64

Source§

impl<'a, VF: ToDatabaseComparison<&'a i8, Postgres>> PgCollectionStorage<VF> for &'a i8

Source§

impl<'a, VF: ToDatabaseComparison<&'a i16, Postgres>> PgCollectionStorage<VF> for &'a i16

Source§

impl<'a, VF: ToDatabaseComparison<&'a i32, Postgres>> PgCollectionStorage<VF> for &'a i32

Source§

impl<'a, VF: ToDatabaseComparison<&'a i64, Postgres>> PgCollectionStorage<VF> for &'a i64

Source§

impl<'a, VF: ToDatabaseComparison<&'a u8, Postgres>> PgCollectionStorage<VF> for &'a u8

Source§

impl<'a, VF: ToDatabaseComparison<&'a u16, Postgres>> PgCollectionStorage<VF> for &'a u16

Source§

impl<'a, VF: ToDatabaseComparison<&'a u32, Postgres>> PgCollectionStorage<VF> for &'a u32

Source§

impl<VF: ToDatabaseComparison<Date, Postgres>> PgCollectionStorage<VF> for Date

Source§

impl<VF: ToDatabaseComparison<Duration, Postgres>> PgCollectionStorage<VF> for Duration

Source§

impl<VF: ToDatabaseComparison<OffsetDateTime, Postgres>> PgCollectionStorage<VF> for OffsetDateTime

Source§

impl<VF: ToDatabaseComparison<PgInterval, Postgres>> PgCollectionStorage<VF> for PgInterval

Source§

impl<VF: ToDatabaseComparison<PrimitiveDateTime, Postgres>> PgCollectionStorage<VF> for PrimitiveDateTime

Source§

impl<VF: ToDatabaseComparison<String, Postgres>> PgCollectionStorage<VF> for String

Source§

impl<VF: ToDatabaseComparison<Time, Postgres>> PgCollectionStorage<VF> for Time

Source§

impl<VF: ToDatabaseComparison<Vec<u8>, Postgres>> PgCollectionStorage<VF> for Vec<u8>

Source§

impl<VF: ToDatabaseComparison<bool, Postgres>> PgCollectionStorage<VF> for bool

Source§

impl<VF: ToDatabaseComparison<f32, Postgres>> PgCollectionStorage<VF> for f32

Source§

impl<VF: ToDatabaseComparison<f64, Postgres>> PgCollectionStorage<VF> for f64

Source§

impl<VF: ToDatabaseComparison<i8, Postgres>> PgCollectionStorage<VF> for i8

Source§

impl<VF: ToDatabaseComparison<i16, Postgres>> PgCollectionStorage<VF> for i16

Source§

impl<VF: ToDatabaseComparison<i32, Postgres>> PgCollectionStorage<VF> for i32

Source§

impl<VF: ToDatabaseComparison<i64, Postgres>> PgCollectionStorage<VF> for i64

Source§

impl<VF: ToDatabaseComparison<u8, Postgres>> PgCollectionStorage<VF> for u8

Source§

impl<VF: ToDatabaseComparison<u16, Postgres>> PgCollectionStorage<VF> for u16

Source§

impl<VF: ToDatabaseComparison<u32, Postgres>> PgCollectionStorage<VF> for u32

Implementors§

Source§

impl<'a, S, VF> PgCollectionStorage<VF> for &'a Confidence<S>

Source§

impl<'a, T, VF> PgCollectionStorage<VF> for &'a Temporal<T>

Available on crate features jiff and time only.

The borrowed half, as Carrier carries one. It reads the same OWNED rows on T: what the wrapper is borrowed does not change which column T lives in.

Source§

impl<'a, VF: ToDatabaseComparison<&'a BeI128, Postgres>> PgCollectionStorage<VF> for &'a BeI128

Source§

impl<'a, VF: ToDatabaseComparison<&'a BeU64, Postgres>> PgCollectionStorage<VF> for &'a BeU64

Source§

impl<'a, VF: ToDatabaseComparison<&'a BeU128, Postgres>> PgCollectionStorage<VF> for &'a BeU128

Source§

impl<'a, VF: ToDatabaseComparison<&'a Count, Postgres>> PgCollectionStorage<VF> for &'a Count

Source§

impl<S, VF> PgCollectionStorage<VF> for Confidence<S>

The confidence’s pair, hand-written for the reason this file’s other hand-written family is: a free type parameter cannot cross pg_collection_storage!’s $ty:ty.

It is in the EDGE-TABLE family for the reason Score was — it owns its encoding rather than sqlx’s, reaching a column through Carrier and implementing no PgHasArrayType, so there is no array type to name. The bound carries the membership: a confidence has this row exactly where the width it measures in has a carrier.

Source§

impl<T, VF> PgCollectionStorage<VF> for Temporal<T>

Available on crate features jiff and time only.

The jiff → time bridge’s row, hand-written for the reason to_filter! hand-writes [u8; N]’s container family: a free type parameter cannot pass through the macro’s $ty:ty.

§It reads T’s row rather than stating one of its own

The where-clause is the whole content: Temporal<T> takes whichever strategies T declared, over the wrapper. Temporal<T> is a conversion wrapper — the column a Vec<jiff::Timestamp> lands in IS the column a Vec<time::OffsetDateTime> lands in — so a row that could contradict T’s would be a wrapper deciding a question about the element it wraps. Delegating makes the two temporal crates agree by CONSTRUCTION rather than for the three storage forms that happen to line up today.

StrategyOver is what carries the element across, and the reason the row cannot simply repeat T’s answer: T’s row states COMPARISONS and a comparison names its element, so what is read is Strategy<T, Postgres> where the wrapper needs Strategy<Temporal<T>, Postgres>.

Deducing the strategy from T: PgHasArrayType + Type + Encode would look equivalent and is not, and i8 is the measurement: it satisfies all three and still declares the edge table, because this crate’s carrier widens it to smallint while sqlx types it "char" — so a deduced row would send Temporal<i8> to an array of the wrong column. The refusal that keeps the strategy DECLARED rather than deduced is the one PgCollectionStorage’s own note makes; this row inherits it instead of re-litigating it.

§The lowering promise is kept on the RE-STATED comparisons, and names no capability

PgCollectionStorage’s two answers each promise ComplexComparison, and the projections this row states are opaque, so each promise is carried as a bound on its own projection. What those bounds are NOT is a capability of T: they say the strategies T declared still lower once their element is the wrapper, and each strategy’s own impl decides what that costs — the column-stored kinds read sqlx’s three off Temporal<T>, which delegate to T, and the edge kinds read Carrier, which does the same. Spelling either of those here would be this row taking a view on a strategy it has not been told yet.

§Both strategies, and the annotation is what asserts which

The projection IS the strategy, so a row that moved is E0308 here rather than a different rendering. BeU64 is the edge case that occurs in practice: a downstream storage form may be any type with a Carrier row — the trait naming one is TemporalStorage, which is public and open — and this crate’s blob carrier is one.

use ingraph::{
  ListFilter, BeU64, Temporal, ToDatabaseComparison,
  comparison::sql::{SqlEdgeComparison, SqlScalarComparison},
};

let _: Option<
  <ListFilter<u64> as ToDatabaseComparison<Temporal<BeU64>, sqlx::Postgres>>::Comparison,
> = None::<SqlEdgeComparison<
  Temporal<BeU64>,
  SqlScalarComparison<Temporal<BeU64>, sqlx::Postgres>,
  sqlx::Postgres,
>>;

The set half reads the other column of the same row, and a Vec<jiff::Timestamp> stored through time is where it lands on the array:

use ingraph::{
  SetFilter, Temporal, ToDatabaseComparison,
  comparison::sql::{SqlScalarComparison, SqlSetComparison},
};

let _: Option<
  <SetFilter<jiff::Timestamp> as ToDatabaseComparison<
    Temporal<time::OffsetDateTime>,
    sqlx::Postgres,
  >>::Comparison,
> = None::<SqlSetComparison<
  Temporal<time::OffsetDateTime>,
  SqlScalarComparison<Temporal<time::OffsetDateTime>, sqlx::Postgres>,
  sqlx::Postgres,
>>;

§The one refusal left, and it names T

A T with NO storage row leaves Temporal<T> without one, because there is no declaration to read — the wrapper does not invent a strategy for an element that has not stated one. The sentence a reader acts on names T, which is where the missing row goes. The two blocks above are this one’s positive twins: stable rustdoc runs a compile_fail block just far enough to see it fail and never checks why, so the pair shares its shape and one half has to be positive.

ⓘ
use ingraph::{ListFilter, Temporal, ToDatabaseComparison};

struct Tag;

let _: Option<
  <ListFilter<Tag> as ToDatabaseComparison<Temporal<Tag>, sqlx::Postgres>>::Comparison,
> = None;
Source§

impl<VF: ToDatabaseComparison<BeI128, Postgres>> PgCollectionStorage<VF> for BeI128

Source§

impl<VF: ToDatabaseComparison<BeU64, Postgres>> PgCollectionStorage<VF> for BeU64

Source§

impl<VF: ToDatabaseComparison<BeU128, Postgres>> PgCollectionStorage<VF> for BeU128

Source§

impl<VF: ToDatabaseComparison<Count, Postgres>> PgCollectionStorage<VF> for Count