foundry_cheatcodes_spec/
items.rs
1use serde::{Deserialize, Serialize};
2use std::{borrow::Cow, fmt};
3
4#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
6#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
7#[serde(rename_all = "camelCase")]
8pub struct Error<'a> {
9 pub name: &'a str,
11 pub description: &'a str,
14 pub declaration: &'a str,
16}
17
18impl fmt::Display for Error<'_> {
19 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20 f.write_str(self.declaration)
21 }
22}
23
24#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
26#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
27#[serde(rename_all = "camelCase")]
28pub struct Event<'a> {
29 pub name: &'a str,
31 pub description: &'a str,
34 pub declaration: &'a str,
36}
37
38impl fmt::Display for Event<'_> {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 f.write_str(self.declaration)
41 }
42}
43
44#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
46#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
47#[serde(rename_all = "camelCase")]
48pub struct Enum<'a> {
49 pub name: &'a str,
51 pub description: &'a str,
54 #[serde(borrow)]
56 pub variants: Cow<'a, [EnumVariant<'a>]>,
57}
58
59impl fmt::Display for Enum<'_> {
60 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61 write!(f, "enum {} {{ ", self.name)?;
62 for (i, variant) in self.variants.iter().enumerate() {
63 if i > 0 {
64 f.write_str(", ")?;
65 }
66 f.write_str(variant.name)?;
67 }
68 f.write_str(" }")
69 }
70}
71
72#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
74#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
75#[serde(rename_all = "camelCase")]
76pub struct EnumVariant<'a> {
77 pub name: &'a str,
79 pub description: &'a str,
82}
83
84#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
86#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
87#[serde(rename_all = "camelCase")]
88pub struct Struct<'a> {
89 pub name: &'a str,
91 pub description: &'a str,
94 #[serde(borrow)]
96 pub fields: Cow<'a, [StructField<'a>]>,
97}
98
99impl fmt::Display for Struct<'_> {
100 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
101 write!(f, "struct {} {{ ", self.name)?;
102 for field in self.fields.iter() {
103 write!(f, "{} {}; ", field.ty, field.name)?;
104 }
105 f.write_str("}")
106 }
107}
108
109#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
111#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
112#[serde(rename_all = "camelCase")]
113pub struct StructField<'a> {
114 pub name: &'a str,
116 pub ty: &'a str,
118 pub description: &'a str,
121}