1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//! Compile-time surface tests for the `sqlx` feature.
//!
//! Nothing here talks to a database; the point is that every trait impl the docs
//! promise actually exists, for identifiers and enums alike.
//!
//! ```text
//! cargo test --test sqlx_compile --features sqlx,versioned
//! ```
#![cfg(all(feature = "sqlx", feature = "versioned"))]
use sqlx::postgres::PgHasArrayType;
use sqlx::{Decode, Encode, Postgres, Type};
fn assert_column<T>()
where
T: Type<Postgres> + for<'q> Encode<'q, Postgres> + for<'r> Decode<'r, Postgres>,
{
}
fn assert_array_column<T: PgHasArrayType>() {}
#[test]
fn identifiers_bind_as_columns_and_arrays() {
use rubo4e::identifiers::*;
macro_rules! check {
($($T:ty),+ $(,)?) => {$(
assert_column::<$T>();
assert_array_column::<$T>();
)+};
}
check!(
AkivId,
Bic,
BilanzierungsgebietId,
BilanzkreisId,
CrId,
EicCode,
Iban,
MaloId,
MarktpartnerId,
MeloId,
NebeId,
NeloId,
ObisCode,
PaketId,
SgId,
SrId,
TrId,
TranchennummerId,
);
}
/// Enums get the same surface as identifiers, arrays included: `Vec<Sparte>`
/// binds to a `TEXT[]` column the way `Vec<MaloId>` does.
#[test]
fn enums_bind_as_columns_and_arrays() {
use rubo4e::current::*;
macro_rules! check {
($($T:ty),+ $(,)?) => {$(
assert_column::<$T>();
assert_array_column::<$T>();
)+};
}
check!(
BoTyp,
ComTyp,
Sparte,
Marktrolle,
Zaehlertyp,
Waehrungscode,
Mengeneinheit,
BdewArtikelnummer,
Messpreistyp,
);
}
/// The `sqlx` feature must stand on its own: both directions round-trip through
/// `&str` via `as_wire` / `from_wire`, so nothing here needs `json`.
#[test]
fn sqlx_surface_needs_no_json_feature() {
use rubo4e::current::Sparte;
assert_eq!(Sparte::Strom.as_wire(), "STROM");
assert_eq!(Sparte::from_wire("STROM"), Ok(Sparte::Strom));
// Decode is lenient by design, matching the serde path.
assert!(Sparte::from_wire("PLASMA").is_err());
}