From 9df0b01689228ac6fc4a018f84eb642b227c63bf Mon Sep 17 00:00:00 2001 From: "Levy A." Date: Thu, 30 Jan 2025 19:58:38 -0300 Subject: [PATCH 1/2] refactor: lower ownership requirement --- bindings/wasm/lib.rs | 2 +- core/types.rs | 4 ++-- tests/integration/common.rs | 6 +++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/bindings/wasm/lib.rs b/bindings/wasm/lib.rs index 1558f09d8..9b34fcb57 100644 --- a/bindings/wasm/lib.rs +++ b/bindings/wasm/lib.rs @@ -192,7 +192,7 @@ fn to_js_value(value: limbo_core::Value) -> JsValue { } limbo_core::Value::Float(f) => JsValue::from(f), limbo_core::Value::Text(t) => JsValue::from_str(t), - limbo_core::Value::Blob(b) => js_sys::Uint8Array::from(b.as_slice()).into(), + limbo_core::Value::Blob(b) => js_sys::Uint8Array::from(b).into(), } } diff --git a/core/types.rs b/core/types.rs index 98075d773..1d478050e 100644 --- a/core/types.rs +++ b/core/types.rs @@ -15,8 +15,8 @@ pub enum Value<'a> { Null, Integer(i64), Float(f64), - Text(&'a String), - Blob(&'a Vec), + Text(&'a str), + Blob(&'a [u8]), } impl Display for Value<'_> { diff --git a/tests/integration/common.rs b/tests/integration/common.rs index 9fbb9eb41..7f8fb1bcd 100644 --- a/tests/integration/common.rs +++ b/tests/integration/common.rs @@ -58,8 +58,12 @@ pub(crate) fn do_flush(conn: &Rc, tmp_db: &TempDatabase) -> anyhow:: Ok(()) } -pub(crate) fn compare_string(a: &String, b: &String) { +pub(crate) fn compare_string(a: impl AsRef, b: impl AsRef) { + let a = a.as_ref(); + let b = b.as_ref(); + assert_eq!(a.len(), b.len(), "Strings are not equal in size!"); + let a = a.as_bytes(); let b = b.as_bytes(); From dcd32e1ec83459d0ae3763aaf84a3310c7a64a8a Mon Sep 17 00:00:00 2001 From: "Levy A." Date: Mon, 3 Feb 2025 16:58:13 -0300 Subject: [PATCH 2/2] fix: clippy + new errors --- tests/integration/fuzz/mod.rs | 4 ++-- tests/integration/query_processing/test_read_path.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/integration/fuzz/mod.rs b/tests/integration/fuzz/mod.rs index 925bfe771..9cab41964 100644 --- a/tests/integration/fuzz/mod.rs +++ b/tests/integration/fuzz/mod.rs @@ -59,8 +59,8 @@ mod tests { limbo_core::Value::Null => rusqlite::types::Value::Null, limbo_core::Value::Integer(x) => rusqlite::types::Value::Integer(*x), limbo_core::Value::Float(x) => rusqlite::types::Value::Real(*x), - limbo_core::Value::Text(x) => rusqlite::types::Value::Text((*x).clone()), - limbo_core::Value::Blob(x) => rusqlite::types::Value::Blob((*x).clone()), + limbo_core::Value::Text(x) => rusqlite::types::Value::Text(x.to_string()), + limbo_core::Value::Blob(x) => rusqlite::types::Value::Blob(x.to_vec()), }) .collect() } diff --git a/tests/integration/query_processing/test_read_path.rs b/tests/integration/query_processing/test_read_path.rs index 55f72c1cc..ef7e30a4b 100644 --- a/tests/integration/query_processing/test_read_path.rs +++ b/tests/integration/query_processing/test_read_path.rs @@ -46,12 +46,12 @@ fn test_statement_bind() -> anyhow::Result<()> { let mut stmt = conn.prepare("select ?, ?1, :named, ?3, ?4")?; - stmt.bind_at(1.try_into()?, Value::Text(&"hello".to_string())); + stmt.bind_at(1.try_into()?, Value::Text("hello")); let i = stmt.parameters().index(":named").unwrap(); stmt.bind_at(i, Value::Integer(42)); - stmt.bind_at(3.try_into()?, Value::Blob(&vec![0x1, 0x2, 0x3])); + stmt.bind_at(3.try_into()?, Value::Blob(&[0x1, 0x2, 0x3])); stmt.bind_at(4.try_into()?, Value::Float(0.5));