Expose derive macro behind feature
This commit is contained in:
parent
b8404df047
commit
ada3578a1d
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -27,6 +27,7 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
|||
name = "decodal"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"decodal-derive",
|
||||
"regex",
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -22,17 +22,15 @@ decodal = "0.1"
|
|||
|
||||
## 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
|
||||
[dependencies]
|
||||
decodal = "0.1"
|
||||
decodal-derive = "0.1"
|
||||
decodal = { version = "0.1", features = ["derive"] }
|
||||
```
|
||||
|
||||
```rust
|
||||
use decodal::{DecodalDecode, DecodalSchema, Engine};
|
||||
use decodal_derive::Decodal;
|
||||
use decodal::{Decodal, DecodalDecode, DecodalSchema, Engine};
|
||||
|
||||
#[derive(Decodal)]
|
||||
struct Service {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,9 @@ categories = ["config", "parser-implementations"]
|
|||
[features]
|
||||
default = ["std"]
|
||||
std = []
|
||||
derive = ["dep:decodal-derive"]
|
||||
regex = ["std", "dep:regex"]
|
||||
|
||||
[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 }
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ pub mod typed;
|
|||
|
||||
pub use ast::{Ast, BinaryOp, CompareOp, Expr, ExprId, Field, Literal, Param};
|
||||
pub use constraints::normalize_constraints;
|
||||
#[cfg(feature = "derive")]
|
||||
pub use decodal_derive::Decodal;
|
||||
pub use diagnostic::{Diagnostic, DiagnosticKind, Result};
|
||||
pub use embedding::{HostField, HostValue};
|
||||
pub use eval::{Engine, format_diagnostic_with};
|
||||
|
|
|
|||
|
|
@ -89,15 +89,14 @@ This matches the runtime model used for Decodal source-defined schema objects.
|
|||
|
||||
## 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:
|
||||
|
||||
- `DecodalSchema`: builds a `HostValue` schema that can be passed to `Engine::bind_global`.
|
||||
- `DecodalDecode`: decodes materialized `Data` back into the Rust type.
|
||||
|
||||
```rust
|
||||
use decodal::{DecodalDecode, DecodalSchema, EmptyLoader, Engine};
|
||||
use decodal_derive::Decodal;
|
||||
use decodal::{Decodal, DecodalDecode, DecodalSchema, EmptyLoader, Engine};
|
||||
|
||||
#[derive(Decodal)]
|
||||
struct Service {
|
||||
|
|
|
|||
|
|
@ -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`.
|
||||
|
||||
```sh
|
||||
cargo publish -p decodal
|
||||
cargo publish -p decodal-derive
|
||||
cargo publish -p decodal
|
||||
```
|
||||
|
||||
Before publishing, run:
|
||||
|
|
@ -38,8 +38,8 @@ Before publishing, run:
|
|||
cargo fmt --check
|
||||
cargo test
|
||||
cargo check -p decodal --no-default-features
|
||||
cargo publish -p decodal --dry-run
|
||||
cargo publish -p decodal-derive --dry-run
|
||||
cargo publish -p decodal --dry-run
|
||||
```
|
||||
|
||||
## Web site and playground
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user