diff --git a/Cargo.lock b/Cargo.lock index 1bcb9ffb6..658ed9c62 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1436,7 +1436,6 @@ dependencies = [ "log", "neo4rs", "rand 0.9.2", - "regex", "reqwest", "serde", "serde_json", diff --git a/rust/cocoindex/Cargo.toml b/rust/cocoindex/Cargo.toml index 1103d32df..ad07d3ce7 100644 --- a/rust/cocoindex/Cargo.toml +++ b/rust/cocoindex/Cargo.toml @@ -14,7 +14,14 @@ default = ["legacy-states-v0"] legacy-states-v0 = [] [dependencies] -cocoindex_utils = { path = "../utils" } +cocoindex_utils = { path = "../utils", features = [ + "bytes_decode", + "reqwest", + "openai", + "neo4rs", + "sqlx", + "yaml", +] } cocoindex_py_utils = { path = "../py_utils" } pyo3 = { workspace = true } diff --git a/rust/utils/Cargo.toml b/rust/utils/Cargo.toml index 3afb99d2e..a1c884253 100644 --- a/rust/utils/Cargo.toml +++ b/rust/utils/Cargo.toml @@ -17,16 +17,25 @@ tokio = { workspace = true } tokio-util = { workspace = true } futures = { workspace = true } blake2 = { workspace = true } -reqwest = { workspace = true } -async-openai = { workspace = true } -neo4rs = { workspace = true } -sqlx = { workspace = true } -encoding_rs = { workspace = true } -regex = { workspace = true } itertools = { workspace = true } indexmap = { workspace = true } hex = { workspace = true } serde_path_to_error = { workspace = true } rand = { workspace = true } -yaml-rust2 = { workspace = true } indenter = { workspace = true } + +encoding_rs = { workspace = true, optional = true } +reqwest = { workspace = true, optional = true } +async-openai = { workspace = true, optional = true } +neo4rs = { workspace = true, optional = true } +sqlx = { workspace = true, optional = true } +yaml-rust2 = { workspace = true, optional = true } + +[features] +default = [] +reqwest = ["dep:reqwest"] +openai = ["dep:async-openai", "reqwest"] +neo4rs = ["dep:neo4rs"] +sqlx = ["dep:sqlx"] +yaml = ["dep:yaml-rust2"] +bytes_decode = ["dep:encoding_rs"] diff --git a/rust/utils/src/lib.rs b/rust/utils/src/lib.rs index 81656ec80..2731525fd 100644 --- a/rust/utils/src/lib.rs +++ b/rust/utils/src/lib.rs @@ -1,12 +1,17 @@ pub mod batching; -pub mod bytes_decode; pub mod concur_control; pub mod db; pub mod deser; pub mod error; pub mod fingerprint; -pub mod http; pub mod immutable; pub mod retryable; + +#[cfg(feature = "bytes_decode")] +pub mod bytes_decode; +#[cfg(feature = "reqwest")] +pub mod http; +#[cfg(feature = "sqlx")] pub mod str_sanitize; +#[cfg(feature = "yaml")] pub mod yaml_ser; diff --git a/rust/utils/src/retryable.rs b/rust/utils/src/retryable.rs index 622f29bc6..e76dcc11f 100644 --- a/rust/utils/src/retryable.rs +++ b/rust/utils/src/retryable.rs @@ -33,6 +33,7 @@ impl IsRetryable for Error { } } +#[cfg(feature = "reqwest")] impl IsRetryable for reqwest::Error { fn is_retryable(&self) -> bool { self.status() == Some(reqwest::StatusCode::TOO_MANY_REQUESTS) @@ -40,6 +41,7 @@ impl IsRetryable for reqwest::Error { } // OpenAI errors - retryable if the underlying reqwest error is retryable +#[cfg(feature = "openai")] impl IsRetryable for async_openai::error::OpenAIError { fn is_retryable(&self) -> bool { match self { @@ -50,6 +52,7 @@ impl IsRetryable for async_openai::error::OpenAIError { } // Neo4j errors - retryable on connection errors and transient errors +#[cfg(feature = "neo4rs")] impl IsRetryable for neo4rs::Error { fn is_retryable(&self) -> bool { match self {