clickhouse.rs
clickhouse.rs copied to clipboard
The fetch API is unsound if used with borrowed types
The current API allows the following code:
let mut cursor = client.query("...").fetch::<MyRow<'_>>()?;
let a = cursor.next().await?;
let b = cursor.next().await?; // <- must be error
We should use something like sqlx::fetch
or wait for GAT stabilization.
Sadly, it will be a breaking change.
Is the issue that you are reusing a temporary and returning a reference to that temporary?
Is there a reason you couldn't change from
pub async fn next<'a, 'b: 'a>(&'a mut self) -> Result<Option<T>> where
T: Deserialize<'b>,
to
pub async fn next<'a>(&'a mut self) -> Result<Option<T>> where
T: Deserialize<'a>,
Yes, this would be a breaking change, but doesn't seem like it would be productively complicated.
Sadly, it's not enough:
--> examples/usage.rs:69:27
|
69 | while let Some(row) = cursor.next().await? {
| ^^^^^^^^^^^^^
| |
| `cursor` was mutably borrowed here in the previous iteration of the loop
| first borrow used here, in later iteration of loop