Skip to content

Commit

Permalink
Merge pull request #591 from hacspec/hax-lib-macros--make-schemars-op…
Browse files Browse the repository at this point in the history
…tional

feat(hax-lib-macros): dependency `schemars`: make optional
  • Loading branch information
W95Psp authored Apr 10, 2024
2 parents fd78dab + 6773328 commit ae1d9ad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cli/subcommands/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ hax-frontend-exporter.workspace = true
hax-diagnostics.workspace = true
hax-cli-options.workspace = true
hax-cli-options-engine.workspace = true
hax-lib-macros-types.workspace = true
hax-lib-macros-types = {workspace = true, features = ["schemars"]}
version_check = "0.9"
toml = "0.8"
4 changes: 3 additions & 1 deletion hax-lib-macros/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ readme.workspace = true
[dependencies]
serde.workspace = true
serde_json.workspace = true
schemars.workspace = true
schemars = {workspace = true, optional = true}
quote.workspace = true
proc-macro2.workspace = true
uuid = { version = "1.5", features = ["v4"] }

[features]
schemars = ["dep:schemars"]
13 changes: 8 additions & 5 deletions hax-lib-macros/types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

/// Each item can be marked with a *u*nique *id*entifier. This is
Expand All @@ -15,7 +14,8 @@ use serde::{Deserialize, Serialize};
/// Morally, we expand `struct Foo { #[refine(x > 3)] x: u32 }` to:
/// 1. `#[uuid(A_UNIQUE_ID_123)] fn refinement(x: u32) -> bool {x > 3}`;
/// 2. `struct Foo { #[refined_by(A_UNIQUE_ID_123)] x: u32 }`.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename = "HaUid")]
pub struct ItemUid {
/// Currently, this is a UUID.
Expand All @@ -31,7 +31,8 @@ impl ItemUid {
}

/// What shall Hax do with an item?
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename = "HaItemStatus")]
pub enum ItemStatus {
/// Include this item in the translation
Expand All @@ -43,7 +44,8 @@ pub enum ItemStatus {
Excluded { modeled_by: Option<String> },
}

#[derive(Debug, Copy, Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename = "HaAssocRole")]
pub enum AssociationRole {
Requires,
Expand All @@ -59,7 +61,8 @@ pub enum AssociationRole {
/// Hax only understands one attribute: `#[hax::json(PAYLOAD)]` where
/// `PAYLOAD` is a JSON serialization of an inhabitant of
/// `AttrPayload`.
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename = "HaPayload")]
pub enum AttrPayload {
ItemStatus(ItemStatus),
Expand Down

0 comments on commit ae1d9ad

Please sign in to comment.