You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat!: Only expose envelope serialization of hugrs and packages (#2167)
Closes#2159
Now `Hugr`s expose `load`/`load_str`/`store`/`store_str` methods instead
of implementing `serde` traits, mirroring `Package`s. This uses
envelopes interternally, so we no longer support row hugr jsons.
`hugr-cli` keeps the backwards compatibility for the moment, by simply
wrapping the jsons with the appropriate header when using the
`--hugr-json` flag.
For users that need it, we define a
[`serde_with`](https://docs.rs/serde_with/3.12.0/serde_with/index.html)
helper to be able to include hugrs and packages inside serde-encoded
structs.
The implementation serializes the hugr into an envelope, and includes it
as a string/bytes value. For backwards compatibility, we temporarily
also try to read Hugr JSONs as a fallback.
```rust
use serde::{Deserialize, Serialize};
use serde_json::json;
use serde_with::{serde_as};
use hugr_core::Hugr;
use hugr_core::package::Package;
use hugr_core::envelope::serde_with::AsStringEnvelope;
#[serde_as]
#[derive(Deserialize, Serialize)]
struct A {
#[serde_as(as = "AsStringEnvelope")]
package: Package,
#[serde_as(as = "Vec<AsStringEnvelope>")]
hugrs: Vec<Hugr>,
}
```
BREAKING CHANGE: `Hugr` and `Package` no longer implement serde traits.
Use envelopes instead. See `AsStringEnvelope` for backwards
compatibility.
---------
Co-authored-by: Seyon Sivarajah <[email protected]>
0 commit comments