lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README | LICENSE

commit 1e2c8796b7ece8d125fdceaae0c2fa1718d58e2d
parent fbf93745ae93b1acf8c60b7c223190dcc6b44c6d
Author: triesap <tyson@radroots.org>
Date:   Sat, 13 Jun 2026 02:10:59 -0700

sql_core: add explicit std feature boundary

- Make std an explicit default feature for SQL core
- Gate native SQLite support behind the std-backed native feature
- Keep owned executor and migration types available through alloc
- Validate native, embedded, no-default, and all-features SQL core lanes

Diffstat:
MCargo.lock | 1-
Mcrates/sql_core/Cargo.toml | 20+++++++++++++++-----
Mcrates/sql_core/src/error.rs | 37++++++++++++++++++++-----------------
Mcrates/sql_core/src/executor_embedded.rs | 5-----
Mcrates/sql_core/src/lib.rs | 13+++++++------
Mcrates/sql_core/src/migrations.rs | 3+++
6 files changed, 45 insertions(+), 34 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -4561,7 +4561,6 @@ dependencies = [ "serde", "serde-wasm-bindgen", "serde_json", - "thiserror 1.0.69", "uuid", "wasm-bindgen", ] diff --git a/crates/sql_core/Cargo.toml b/crates/sql_core/Cargo.toml @@ -16,23 +16,33 @@ readme = "README" crate-type = ["rlib"] [features] -web = [] +default = ["std"] +std = [ + "dep:chrono", + "dep:uuid", + "serde/std", + "serde_json/std", +] +web = ["std"] bridge = [ + "std", "web", "dep:radroots_sql_wasm_bridge", "dep:serde-wasm-bindgen", "dep:wasm-bindgen", ] -native = ["dep:rusqlite"] +native = [ + "std", + "dep:rusqlite", +] embedded = [] [dependencies] serde_json = { workspace = true } -thiserror = { workspace = true } radroots_sql_wasm_bridge = { workspace = true, optional = true } wasm-bindgen = { workspace = true, optional = true } serde-wasm-bindgen = { workspace = true, optional = true } rusqlite = { workspace = true, features = ["bundled"], optional = true } -chrono = { workspace = true } +chrono = { workspace = true, optional = true } serde = { workspace = true } -uuid = { workspace = true } +uuid = { workspace = true, optional = true } diff --git a/crates/sql_core/src/error.rs b/crates/sql_core/src/error.rs @@ -1,27 +1,14 @@ -#![cfg_attr(any(feature = "embedded", target_os = "espidf"), no_std)] - -#[cfg(any(feature = "embedded", target_os = "espidf"))] -extern crate alloc; - +use alloc::string::{String, ToString}; +use core::fmt::{Display, Formatter}; use serde::Serialize; -use thiserror::Error; - -#[cfg(any(feature = "embedded", target_os = "espidf"))] -use alloc::string::String; -#[derive(Error, Debug, Clone, Serialize)] +#[derive(Debug, Clone, Serialize)] pub enum SqlError { - #[error("invalid argument: {0}")] InvalidArgument(String), - #[error("{0} not found")] NotFound(String), - #[error("serialization error: {0}")] SerializationError(String), - #[error("invalid query: {0}")] InvalidQuery(String), - #[error("internal error")] Internal, - #[error("unsupported on this platform")] UnsupportedPlatform, } @@ -42,13 +29,29 @@ impl SqlError { } } +impl Display for SqlError { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { + match self { + SqlError::InvalidArgument(value) => write!(f, "invalid argument: {value}"), + SqlError::NotFound(value) => write!(f, "{value} not found"), + SqlError::SerializationError(value) => write!(f, "serialization error: {value}"), + SqlError::InvalidQuery(value) => write!(f, "invalid query: {value}"), + SqlError::Internal => f.write_str("internal error"), + SqlError::UnsupportedPlatform => f.write_str("unsupported on this platform"), + } + } +} + +#[cfg(feature = "std")] +impl std::error::Error for SqlError {} + impl From<serde_json::Error> for SqlError { fn from(e: serde_json::Error) -> Self { SqlError::SerializationError(e.to_string()) } } -#[cfg(feature = "native")] +#[cfg(all(feature = "native", feature = "std"))] impl From<rusqlite::Error> for SqlError { fn from(e: rusqlite::Error) -> Self { SqlError::InvalidQuery(e.to_string()) diff --git a/crates/sql_core/src/executor_embedded.rs b/crates/sql_core/src/executor_embedded.rs @@ -1,8 +1,3 @@ -#![cfg(any(feature = "embedded", target_os = "espidf"))] -#![no_std] - -extern crate alloc; - use alloc::string::String; use crate::{ExecOutcome, SqlExecutor, error::SqlError}; diff --git a/crates/sql_core/src/lib.rs b/crates/sql_core/src/lib.rs @@ -1,6 +1,5 @@ -#![cfg_attr(any(feature = "embedded", target_os = "espidf"), no_std)] +#![cfg_attr(not(feature = "std"), no_std)] -#[cfg(any(feature = "embedded", target_os = "espidf"))] extern crate alloc; pub mod error; @@ -18,11 +17,11 @@ mod executor_wasm; #[cfg(all(feature = "bridge", target_arch = "wasm32"))] pub use executor_wasm::WasmSqlExecutor; -#[cfg(feature = "native")] +#[cfg(all(feature = "native", feature = "std"))] mod executor_sqlite; -#[cfg(feature = "native")] +#[cfg(all(feature = "native", feature = "std"))] pub use executor_sqlite::SqliteExecutor; -#[cfg(feature = "native")] +#[cfg(all(feature = "native", feature = "std"))] pub mod sqlite_util; #[cfg(feature = "embedded")] @@ -30,11 +29,13 @@ mod executor_embedded; #[cfg(feature = "embedded")] pub use executor_embedded::EmbeddedSqlExecutor; -#[cfg(not(any(feature = "embedded", target_os = "espidf")))] +#[cfg(feature = "std")] pub mod utils; pub use error::SqlError; +use alloc::string::String; + #[derive(Clone, Copy, Debug)] pub struct ExecOutcome { pub changes: i64, diff --git a/crates/sql_core/src/migrations.rs b/crates/sql_core/src/migrations.rs @@ -1,3 +1,6 @@ +use alloc::string::ToString; +use alloc::vec::Vec; + use crate::SqlExecutor; use crate::error::SqlError; use serde_json::{Value, json};