Skip to content

Commit 95e55a4

Browse files
committed
fix(clinvoice_adapter_postgres): workaround for rust-lang/rust#39959
1 parent 2a74a0c commit 95e55a4

File tree

3 files changed

+28
-53
lines changed

3 files changed

+28
-53
lines changed
Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
mod display;
2-
31
use core::fmt::Display;
42

53
use clinvoice_adapter::fmt::SnakeCase;
@@ -12,54 +10,34 @@ use clinvoice_adapter::fmt::SnakeCase;
1210
/// Created to avoid using `format!` every time this pattern was required, thus eagerly allocating
1311
/// a [`String`] even if it was only needed for pushing to another [`String`].
1412
#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15-
pub(crate) struct PgLocationRecursiveCte<TCurrent, TPrev>(SnakeCase<TPrev, TCurrent>)
16-
where
17-
TCurrent: Display,
18-
TPrev: Display;
13+
pub(crate) struct PgLocationRecursiveCte;
1914

20-
impl<TCurrent, TPrev> PgLocationRecursiveCte<TCurrent, TPrev>
21-
where
22-
TCurrent: Display,
23-
TPrev: Display,
15+
impl PgLocationRecursiveCte
2416
{
2517
/// # Summary
2618
///
27-
/// Return the previous occurance of the [`PgLocationRecursiveCte`], if there is one.
28-
pub(crate) const fn prev(&self) -> Option<&TPrev>
19+
/// Create a new recursive CTE identifier for a [`PgLocation`].
20+
pub(crate) const fn new() -> SnakeCase<&'static str, &'static str>
2921
{
30-
if let Some((left, _)) = self.0.slice_end()
31-
{
32-
return Some(left);
33-
}
34-
35-
None
22+
SnakeCase::new("location")
3623
}
3724

3825
/// # Summary
3926
///
4027
/// Get the [`PgLocationRecursiveCte`] representing the [`Location`](clinvoice_schema::Location) this one.
41-
pub(crate) fn outer(self) -> PgLocationRecursiveCte<&'static str, SnakeCase<TPrev, TCurrent>>
42-
{
43-
PgLocationRecursiveCte(self.0.push("outer"))
44-
}
45-
}
46-
47-
impl PgLocationRecursiveCte<&'static str, &'static str>
48-
{
49-
/// # Summary
50-
///
51-
/// Create a new recursive CTE identifier for a [`PgLocation`].
52-
pub(crate) const fn new() -> Self
28+
pub(crate) const fn outer<T>(t: T) -> SnakeCase<T, &'static str>
29+
where
30+
T: Display,
5331
{
54-
Self(SnakeCase::new("location"))
32+
SnakeCase::Body(t, "outer")
5533
}
5634

5735
/// # Summary
5836
///
5937
/// The ident used to refer to the rows matching some [`MatchLocation`] at the end of a `WITH
6038
/// RECURSIVE`.
61-
pub(crate) const fn report() -> Self
39+
pub(crate) const fn report() -> SnakeCase<&'static str, &'static str>
6240
{
63-
Self(SnakeCase::new("location_report"))
41+
SnakeCase::new("location_report")
6442
}
6543
}

crates/adapters/clinvoice_adapter_postgres/src/fmt/location_recursive_cte/display.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

crates/adapters/clinvoice_adapter_postgres/src/schema/location.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ impl PgLocation
3333
/// Generate multiple Common Table Expressions for a recursive query.
3434
fn generate_cte<TCurrent, TPrev, const FIRST: bool>(
3535
query: &mut QueryBuilder<Postgres>,
36-
ident: PgLocationRecursiveCte<TCurrent, TPrev>,
36+
ident: TCurrent, /* HACK: this parameter should be `ident: SnakeCase<TPrev, TCurrent>` after rust-lang/rust#39959 */
3737
match_condition: &MatchLocation,
38+
prev: Option<TPrev>, /* HACK: this parameter is necessary because we can't use `ident: SnakeCase` because of rust-lang/rust#39959 */
3839
) where
3940
TCurrent: Display,
4041
TPrev: Display,
@@ -58,11 +59,11 @@ impl PgLocation
5859
.push("FROM locations")
5960
.push(ALIAS_OUTER);
6061

61-
if let Some(prev) = ident.prev()
62+
if let Some(p) = prev
6263
{
6364
separated
6465
.push("JOIN")
65-
.push(prev)
66+
.push(p)
6667
.push(ALIAS_INNER)
6768
.push("ON (")
6869
.push_unseparated(outer_columns.id)
@@ -103,7 +104,13 @@ impl PgLocation
103104
MatchOuterLocation::Some(ref outer) =>
104105
{
105106
query.push(',');
106-
generate_cte::<_, _, false>(query, ident.outer(), outer)
107+
generate_cte::<_, _, false>(
108+
query,
109+
// HACK: remove `.to_string()` after rust-lang/rust#39959
110+
PgLocationRecursiveCte::outer(&ident).to_string(),
111+
outer,
112+
Some(&ident),
113+
)
107114
},
108115
MatchOuterLocation::Any | MatchOuterLocation::None =>
109116
{
@@ -148,7 +155,12 @@ impl PgLocation
148155

149156
let mut query = QueryBuilder::new("WITH RECURSIVE ");
150157

151-
generate_cte::<_, _, true>(&mut query, PgLocationRecursiveCte::new(), match_condition);
158+
generate_cte::<_, _, true>(
159+
&mut query,
160+
PgLocationRecursiveCte::new(),
161+
match_condition,
162+
None::<&str>,
163+
);
152164

153165
query.push(' ');
154166
query

0 commit comments

Comments
 (0)