Skip to content

Commit

Permalink
feat: blueprint-serde crate (#429)
Browse files Browse the repository at this point in the history
* feat: `blueprint-serde` crate

This crates lets us convert to and from the `Field` type easily with `serde`'s `Serialize` and `Deserialize` traits.
This will allow for custom types in job parameters, as well as making it easier overall to convert between these types.

The crate adds two public functions:

* `to_field` - Convert any `Serialize` type into a `Field`
* `from_field` - Attempt to convert a `Field` into a `DeserializeOwned` type

While mostly useful for `Field::Struct`, one can also do:

```rust
let age: u8 = gadget_blueprint_serde::from_field(Field::Uint8(40)).unwrap();
```

Or conversion for any primitive type, if they wanted.

* chore(gadget-blueprint-serde): simplify primitive & struct deserialization

* fix(gadget-blueprint-serde): add unit serialization

* chore(gadget-blueprint-serde): move `serde-test` to dev dependencies

* chore(gadget-blueprint-serde): improve docs and add examples

* feat(gadget-blueprint-serde): force `#![no_std]`

* feat(gadget-blueprint-serde): add `std` feature

* chore(gadget-blueprint-serde): add tests for enums

* chore(gadget-blueprint-serde): defer enum variant deserializing

* chore: bump `tangle-subxt`
  • Loading branch information
Serial-ATA authored Nov 5, 2024
1 parent 71ea78a commit c6d9ffe
Show file tree
Hide file tree
Showing 8 changed files with 1,490 additions and 3 deletions.
24 changes: 22 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ members = [
"gadget-io",
"blueprint-test-utils",
"blueprint-manager",
"blueprint-serde",
"sdk",
"macros/blueprint-proc-macro",
"macros/blueprint-proc-macro-core",
Expand All @@ -37,13 +38,16 @@ unused_import_braces = "deny"
pedantic = { level = "deny", priority = -1 }
all = { level = "deny", priority = -1 }
single_match_else = "allow"
uninlined_format_args = "allow"
needless_late_init = "allow"

[workspace.lints.rustdoc]
broken_intra_doc_links = "deny"

[workspace.dependencies]
gadget-io = { version = "0.0.4", path = "./gadget-io", default-features = false }
blueprint-manager = { version = "0.1.1", path = "./blueprint-manager" }
blueprint-serde = { version = "0.1.0", path = "./blueprint-serde", package = "gadget-blueprint-serde" }
blueprint-test-utils = { path = "./blueprint-test-utils" }
gadget-sdk = { path = "./sdk", default-features = false, version = "0.2.3" }

Expand All @@ -61,7 +65,7 @@ cargo-tangle = { path = "./cli", version = "0.2.1" }
cargo_metadata = { version = "0.18.1" }

# Tangle-related dependencies
tangle-subxt = { version = "0.4.0", default-features = false }
tangle-subxt = { version = "0.5.0", default-features = false }
subxt-signer = { version = "0.37.0", default-features = false }
subxt = { version = "0.37.0", default-features = false }
subxt-core = { version = "0.37.0", default-features = false }
Expand Down Expand Up @@ -117,6 +121,7 @@ multiaddr = { version = "0.18.1", default-features = false }
nix = { version = "0.29.0", features = ["process", "signal"] }
num-bigint = "0.4.6"
parking_lot = "0.12.3"
paste = "1.0.15"
proc-macro2 = "1.0"
prometheus = { version = "0.13.4", default-features = false }
quote = "1.0"
Expand All @@ -126,6 +131,7 @@ rustdoc-types = "0.31.0"
schnorrkel = { version = "0.11.4", default-features = false, features = ["preaudit_deprecated", "getrandom"] }
serde = { version = "1.0.208", default-features = false }
serde_json = "1.0"
serde_test = "1.0.177"
sha2 = "0.10.8"
sqlx = "=0.7.3"
syn = "2.0.75"
Expand Down
23 changes: 23 additions & 0 deletions blueprint-serde/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "gadget-blueprint-serde"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true

[dependencies]
paste.workspace = true
serde.workspace = true
tangle-subxt.workspace = true

[dev-dependencies]
serde_test.workspace = true

[lints]
workspace = true

[features]
default = ["std"]
std = []
Loading

0 comments on commit c6d9ffe

Please sign in to comment.