Remove ouroboros dev dependencies

Keep only self_cell
This commit is contained in:
gwenn 2025-01-25 16:05:36 +01:00
parent 9460849521
commit 508e5058c4
4 changed files with 29 additions and 59 deletions

View File

@ -144,7 +144,6 @@ tempfile = "3.1.0"
regex = "1.5.5" regex = "1.5.5"
uuid = { version = "1.0", features = ["v4"] } uuid = { version = "1.0", features = ["v4"] }
unicase = "2.6.0" unicase = "2.6.0"
ouroboros = "0.18"
self_cell = "1.1.0" self_cell = "1.1.0"
# Use `bencher` over criterion because it builds much faster, # Use `bencher` over criterion because it builds much faster,
# and we don't have many benchmarks # and we don't have many benchmarks

View File

@ -1,25 +1,23 @@
extern crate rusqlite; extern crate rusqlite;
use ouroboros::self_referencing;
use rusqlite::{CachedStatement, Connection, Result, Rows}; use rusqlite::{CachedStatement, Connection, Result, Rows};
use self_cell::{self_cell, MutBorrow};
#[self_referencing] type RowsRef<'a> = Rows<'a>;
struct OwningRows<'conn> {
stmt: CachedStatement<'conn>, self_cell!(
#[borrows(mut stmt)] struct OwningRows<'conn> {
#[covariant] owner: MutBorrow<CachedStatement<'conn>>,
rows: Rows<'this>, #[covariant]
} dependent: RowsRef,
}
);
fn main() -> Result<()> { fn main() -> Result<()> {
let conn = Connection::open_in_memory()?; let conn = Connection::open_in_memory()?;
let stmt = conn.prepare_cached("SELECT 1")?; let stmt = conn.prepare_cached("SELECT 1")?;
let mut or = OwningRowsTryBuilder { let mut or = OwningRows::try_new(MutBorrow::new(stmt), |s| s.borrow_mut().query([]))?;
stmt, or.with_dependent_mut(|_stmt, rows| -> Result<()> {
rows_builder: |s| s.query([]),
}
.try_build()?;
or.with_rows_mut(|rows| -> Result<()> {
while let Some(row) = rows.next()? { while let Some(row) = rows.next()? {
assert_eq!(Ok(1), row.get(0)); assert_eq!(Ok(1), row.get(0));
} }

View File

@ -1,27 +0,0 @@
extern crate rusqlite;
use rusqlite::{CachedStatement, Connection, Result, Rows};
use self_cell::{self_cell, MutBorrow};
type RowsRef<'a> = Rows<'a>;
self_cell!(
struct OwningRows<'conn> {
owner: MutBorrow<CachedStatement<'conn>>,
#[covariant]
dependent: RowsRef,
}
);
fn main() -> Result<()> {
let conn = Connection::open_in_memory()?;
let stmt = conn.prepare_cached("SELECT 1")?;
let mut or = OwningRows::try_new(MutBorrow::new(stmt), |s| s.borrow_mut().query([]))?;
or.with_dependent_mut(|_stmt, rows| -> Result<()> {
while let Some(row) = rows.next()? {
assert_eq!(Ok(1), row.get(0));
}
Ok(())
})?;
Ok(())
}

View File

@ -1,28 +1,28 @@
extern crate rusqlite; extern crate rusqlite;
use ouroboros::self_referencing;
use rusqlite::{CachedStatement, Connection, Result, Rows}; use rusqlite::{CachedStatement, Connection, Result, Rows};
use self_cell::{self_cell, MutBorrow};
/// Caveat: single statement at a time for one connection. type CachedStatementRef<'a> = CachedStatement<'a>;
/// But if you need multiple statements, you can still create your own struct
/// with multiple fields (one for each statement). // Caveat: single statement at a time for one connection.
#[self_referencing] // But if you need multiple statements, you can still create your own struct
struct OwningStatement { // with multiple fields (one for each statement).
conn: Connection, self_cell!(
#[borrows(conn)] struct OwningStatement {
#[covariant] owner: MutBorrow<Connection>,
stmt: CachedStatement<'this>, #[covariant]
} dependent: CachedStatementRef,
}
);
fn main() -> Result<()> { fn main() -> Result<()> {
let conn = Connection::open_in_memory()?; let conn = Connection::open_in_memory()?;
let mut os = OwningStatementTryBuilder { let mut os = OwningStatement::try_new(MutBorrow::new(conn), |s| {
conn, s.borrow_mut().prepare_cached("SELECT 1")
stmt_builder: |c| c.prepare_cached("SELECT 1"), })?;
}
.try_build()?;
let mut rows = os.with_stmt_mut(|stmt| -> Result<Rows<'_>> { stmt.query([]) })?; let mut rows = os.with_dependent_mut(|_conn, stmt| -> Result<Rows<'_>> { stmt.query([]) })?;
while let Some(row) = rows.next()? { while let Some(row) = rows.next()? {
assert_eq!(Ok(1), row.get(0)); assert_eq!(Ok(1), row.get(0));
} }