Skip to content

Instantly share code, notes, and snippets.

@Gozala
Created September 3, 2025 22:13
Show Gist options
  • Save Gozala/ee413afc0b978f22d7d6075878be2d4c to your computer and use it in GitHub Desktop.
Save Gozala/ee413afc0b978f22d7d6075878be2d4c to your computer and use it in GitHub Desktop.
error[E0308]: mismatched types
--> rust/dialog-query/src/join.rs:90:9
|
51 | pub fn empty() -> impl EvaluationPlan {
| -------------------
| |
| the expected opaque type
| one of the found opaque types
...
55 | pub fn and<L: EvaluationPlan, R: EvaluationPlan>(left: L, right: R) -> impl EvaluationPlan {
| ------------------- one of the found opaque types
...
89 | let mut c = empty();
| ------- expected due to this value
90 | c = and(c, left);
| ^^^^^^^^^^^^ expected opaque type, found a different opaque type
|
= note: expected opaque type `impl EvaluationPlan`
found opaque type `impl EvaluationPlan`
= note: distinct uses of `impl Trait` result in different opaque types
error[E0308]: mismatched types
--> rust/dialog-query/src/join.rs:91:9
|
51 | pub fn empty() -> impl EvaluationPlan {
| -------------------
| |
| the expected opaque type
| one of the found opaque types
...
55 | pub fn and<L: EvaluationPlan, R: EvaluationPlan>(left: L, right: R) -> impl EvaluationPlan {
| ------------------- one of the found opaque types
...
89 | let mut c = empty();
| ------- expected due to this value
90 | c = and(c, left);
91 | c = and(c, middle);
| ^^^^^^^^^^^^^^ expected opaque type, found a different opaque type
|
= note: expected opaque type `impl EvaluationPlan`
found opaque type `impl EvaluationPlan`
= note: distinct uses of `impl Trait` result in different opaque types
error[E0308]: mismatched types
--> rust/dialog-query/src/join.rs:92:9
|
51 | pub fn empty() -> impl EvaluationPlan {
| -------------------
| |
| the expected opaque type
| one of the found opaque types
...
55 | pub fn and<L: EvaluationPlan, R: EvaluationPlan>(left: L, right: R) -> impl EvaluationPlan {
| ------------------- one of the found opaque types
...
89 | let mut c = empty();
| ------- expected due to this value
...
92 | c = and(c, right);
| ^^^^^^^^^^^^^ expected opaque type, found a different opaque type
|
= note: expected opaque type `impl EvaluationPlan`
found opaque type `impl EvaluationPlan`
= note: distinct uses of `impl Trait` result in different opaque types
use crate::plan::{EvaluationContext, EvaluationPlan};
use crate::query::Store;
use crate::syntax::VariableScope;
use crate::Selection;
use async_stream::try_stream;
/// A composable join structure that can represent zero, one, or two evaluation plans
#[derive(Debug, Clone)]
pub struct And<L: EvaluationPlan, R: EvaluationPlan> {
left: L,
right: R,
}
impl<L: EvaluationPlan, R: EvaluationPlan> And<L, R> {
/// Create a new `ComposableJoin` with two evaluation plans
pub fn new(left: L, right: R) -> Self {
And { left, right }
}
/// Create a new `ComposableJoin` with two evaluation plans
pub fn and<P: EvaluationPlan>(self, right: P) -> And<Self, P> {
And { left: self, right }
}
}
#[derive(Debug, Clone)]
pub struct Through;
impl Through {
pub fn new() -> impl EvaluationPlan {
Through
}
pub fn and<P: EvaluationPlan>(self, right: P) -> impl EvaluationPlan {
and(self, right)
}
}
impl EvaluationPlan for Through {
fn cost(&self) -> usize {
0
}
fn provides(&self) -> VariableScope {
VariableScope::new()
}
fn evaluate<S: Store, M: Selection>(&self, context: EvaluationContext<S, M>) -> impl Selection {
context.selection
}
}
pub fn empty() -> impl EvaluationPlan {
Through::new()
}
pub fn and<L: EvaluationPlan, R: EvaluationPlan>(left: L, right: R) -> impl EvaluationPlan {
And::new(left, right)
}
impl<L: EvaluationPlan, R: EvaluationPlan> EvaluationPlan for And<L, R> {
fn cost(&self) -> usize {
self.left.cost() + self.right.cost()
}
fn provides(&self) -> VariableScope {
self.left.provides().extend(self.right.provides())
}
fn evaluate<S: Store, M: Selection>(&self, context: EvaluationContext<S, M>) -> impl Selection {
try_stream! {
let store = context.store.clone();
let left_selection = self.left.evaluate(context);
let right_selection = self.right.evaluate(EvaluationContext {
selection: left_selection,
store
});
for await frame in right_selection {
yield frame?;
}
}
}
}
fn test_building_join<L: EvaluationPlan, M: EvaluationPlan, R: EvaluationPlan>(
left: L,
middle: M,
right: R,
) -> impl EvaluationPlan {
let mut c = empty();
c = and(c, left);
c = and(c, middle);
c = and(c, right);
c
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment