From 6e54f4c1ea9561a0c5b5e17f4aa0f6643f2f9330 Mon Sep 17 00:00:00 2001 From: jkomyno Date: Tue, 15 Oct 2024 12:09:16 +0400 Subject: [PATCH] fix(crosstarget-utils): fixes on regex and derive_more --- Cargo.lock | 1 + Cargo.toml | 1 + libs/crosstarget-utils/Cargo.toml | 3 ++- libs/crosstarget-utils/src/common/regex.rs | 2 +- libs/crosstarget-utils/src/wasm/regex.rs | 9 +++------ .../connectors/mongodb-query-connector/Cargo.toml | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9dee32574c6..7c4c52dda16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -923,6 +923,7 @@ dependencies = [ name = "crosstarget-utils" version = "0.1.0" dependencies = [ + "derive_more", "enumflags2", "futures", "js-sys", diff --git a/Cargo.toml b/Cargo.toml index f2000ba619d..930f95e0c8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,6 +51,7 @@ tokio = { version = "1", features = [ "time", ] } chrono = { version = "0.4.38", features = ["serde"] } +derive_more = "0.99.17" user-facing-errors = { path = "./libs/user-facing-errors" } uuid = { version = "1", features = ["serde", "v4", "v7", "js"] } indoc = "2.0.1" diff --git a/libs/crosstarget-utils/Cargo.toml b/libs/crosstarget-utils/Cargo.toml index 6d1f2c6f7df..8dd311e292d 100644 --- a/libs/crosstarget-utils/Cargo.toml +++ b/libs/crosstarget-utils/Cargo.toml @@ -6,8 +6,9 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -futures = "0.3" +derive_more.workspace = true enumflags2.workspace = true +futures = "0.3" [target.'cfg(target_arch = "wasm32")'.dependencies] js-sys.workspace = true diff --git a/libs/crosstarget-utils/src/common/regex.rs b/libs/crosstarget-utils/src/common/regex.rs index 51542fb0deb..825d3e85d6c 100644 --- a/libs/crosstarget-utils/src/common/regex.rs +++ b/libs/crosstarget-utils/src/common/regex.rs @@ -1,7 +1,7 @@ use derive_more::Display; #[derive(Debug, Display)] -#[display("Regular expression error: {message}")] +#[display(fmt = "Regular expression error: {message}")] pub struct RegExpError { pub message: String, } diff --git a/libs/crosstarget-utils/src/wasm/regex.rs b/libs/crosstarget-utils/src/wasm/regex.rs index c792ec410d9..4ca60b82721 100644 --- a/libs/crosstarget-utils/src/wasm/regex.rs +++ b/libs/crosstarget-utils/src/wasm/regex.rs @@ -24,17 +24,14 @@ impl RegExpCompat for RegExp { fn captures(&self, message: &str) -> Option> { let matches = self.inner.exec(message); matches.map(|matches| { - let mut captures = Vec::new(); + let mut captures: Vec = Vec::new(); for i in 0..matches.length() { let match_value = matches.get(i); // We keep the same number of captures as the number of groups in the regex pattern, // but we guarantee that the captures are always strings. - if match_value.is_string() { - captures.push(match_value.as_string().unwrap()); - } else { - captures.push(String::new()); - } + let capture: String = match_value.try_into().ok().unwrap_or_default(); + captures.push(capture); } captures }) diff --git a/query-engine/connectors/mongodb-query-connector/Cargo.toml b/query-engine/connectors/mongodb-query-connector/Cargo.toml index e66ca420402..386c694b267 100644 --- a/query-engine/connectors/mongodb-query-connector/Cargo.toml +++ b/query-engine/connectors/mongodb-query-connector/Cargo.toml @@ -22,7 +22,7 @@ uuid.workspace = true indexmap.workspace = true query-engine-metrics = { path = "../../metrics" } cuid = { git = "https://github.com/prisma/cuid-rust", branch = "wasm32-support" } -derive_more = "0.99.17" +derive_more.workspace = true [dependencies.query-structure] path = "../../query-structure"