Expose derive macro behind feature

This commit is contained in:
Keisuke Hirata 2026-06-26 00:59:39 +09:00
parent b8404df047
commit ada3578a1d
No known key found for this signature in database
6 changed files with 12 additions and 10 deletions

1
Cargo.lock generated
View File

@ -27,6 +27,7 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
name = "decodal" name = "decodal"
version = "0.1.1" version = "0.1.1"
dependencies = [ dependencies = [
"decodal-derive",
"regex", "regex",
] ]

View File

@ -22,17 +22,15 @@ decodal = "0.1"
## Derive support ## Derive support
For embedded Rust applications, `decodal-derive` can generate a Decodal schema and typed decoder from a Rust struct. For embedded Rust applications, Decodal can generate a schema and typed decoder from a Rust struct with the `derive` feature.
```toml ```toml
[dependencies] [dependencies]
decodal = "0.1" decodal = { version = "0.1", features = ["derive"] }
decodal-derive = "0.1"
``` ```
```rust ```rust
use decodal::{DecodalDecode, DecodalSchema, Engine}; use decodal::{Decodal, DecodalDecode, DecodalSchema, Engine};
use decodal_derive::Decodal;
#[derive(Decodal)] #[derive(Decodal)]
struct Service { struct Service {

View File

@ -13,7 +13,9 @@ categories = ["config", "parser-implementations"]
[features] [features]
default = ["std"] default = ["std"]
std = [] std = []
derive = ["dep:decodal-derive"]
regex = ["std", "dep:regex"] regex = ["std", "dep:regex"]
[dependencies] [dependencies]
decodal-derive = { version = "0.1.1", path = "../decodal-derive", optional = true }
regex = { version = "1.10", default-features = false, features = ["std", "unicode-perl"], optional = true } regex = { version = "1.10", default-features = false, features = ["std", "unicode-perl"], optional = true }

View File

@ -16,6 +16,8 @@ pub mod typed;
pub use ast::{Ast, BinaryOp, CompareOp, Expr, ExprId, Field, Literal, Param}; pub use ast::{Ast, BinaryOp, CompareOp, Expr, ExprId, Field, Literal, Param};
pub use constraints::normalize_constraints; pub use constraints::normalize_constraints;
#[cfg(feature = "derive")]
pub use decodal_derive::Decodal;
pub use diagnostic::{Diagnostic, DiagnosticKind, Result}; pub use diagnostic::{Diagnostic, DiagnosticKind, Result};
pub use embedding::{HostField, HostValue}; pub use embedding::{HostField, HostValue};
pub use eval::{Engine, format_diagnostic_with}; pub use eval::{Engine, format_diagnostic_with};

View File

@ -89,15 +89,14 @@ This matches the runtime model used for Decodal source-defined schema objects.
## Typed Rust integration ## Typed Rust integration
Hosts can use `decodal-derive` to keep a Rust struct, the Decodal schema, and the decoded result in sync. Hosts can enable the `derive` feature on `decodal` to keep a Rust struct, the Decodal schema, and the decoded result in sync.
The derive implements two traits from the `decodal` crate: The derive implements two traits from the `decodal` crate:
- `DecodalSchema`: builds a `HostValue` schema that can be passed to `Engine::bind_global`. - `DecodalSchema`: builds a `HostValue` schema that can be passed to `Engine::bind_global`.
- `DecodalDecode`: decodes materialized `Data` back into the Rust type. - `DecodalDecode`: decodes materialized `Data` back into the Rust type.
```rust ```rust
use decodal::{DecodalDecode, DecodalSchema, EmptyLoader, Engine}; use decodal::{Decodal, DecodalDecode, DecodalSchema, EmptyLoader, Engine};
use decodal_derive::Decodal;
#[derive(Decodal)] #[derive(Decodal)]
struct Service { struct Service {

View File

@ -28,8 +28,8 @@ Workspace support crates such as `decodal-cli` and `decodal-wasm` are not publis
The project is dual licensed as `MIT OR Apache-2.0`. The project is dual licensed as `MIT OR Apache-2.0`.
```sh ```sh
cargo publish -p decodal
cargo publish -p decodal-derive cargo publish -p decodal-derive
cargo publish -p decodal
``` ```
Before publishing, run: Before publishing, run:
@ -38,8 +38,8 @@ Before publishing, run:
cargo fmt --check cargo fmt --check
cargo test cargo test
cargo check -p decodal --no-default-features cargo check -p decodal --no-default-features
cargo publish -p decodal --dry-run
cargo publish -p decodal-derive --dry-run cargo publish -p decodal-derive --dry-run
cargo publish -p decodal --dry-run
``` ```
## Web site and playground ## Web site and playground