Skip to content

Commit 3fb6090

Browse files
daymdancrossnyc
authored andcommitted
Cargo: Introduce new features "serde" and "schemars".
1 parent 0e598af commit 3fb6090

File tree

4 files changed

+64
-42
lines changed

4 files changed

+64
-42
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ zerocopy = "0.6"
3030
[features]
3131
default = []
3232
std = []
33+
serde = []
34+
schemars = ["std", "serde"]

src/ondisk.rs

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ pub const EFH_POSITION: [Location; 6] = [
4949
];
5050

5151
#[repr(u8)]
52-
#[derive(Debug, PartialEq, FromPrimitive, ToPrimitive, Clone, Copy, serde::Deserialize, serde::Serialize)]
53-
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
52+
#[derive(Debug, PartialEq, FromPrimitive, ToPrimitive, Clone, Copy)]
53+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
54+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
5455
#[non_exhaustive]
5556
pub enum SpiReadMode {
5657
Normal33_33Mhz = 0b000, // up to 33.33 MHz
@@ -64,8 +65,9 @@ pub enum SpiReadMode {
6465
}
6566

6667
#[repr(u8)]
67-
#[derive(Debug, PartialEq, FromPrimitive, ToPrimitive, Clone, Copy, serde::Deserialize, serde::Serialize)]
68-
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
68+
#[derive(Debug, PartialEq, FromPrimitive, ToPrimitive, Clone, Copy)]
69+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
70+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
6971
#[non_exhaustive]
7072
pub enum SpiFastSpeedNew {
7173
_66_66MHz = 0,
@@ -110,8 +112,9 @@ impl Setter<EfhBulldozerSpiMode> for EfhBulldozerSpiMode {
110112
}
111113

112114
#[repr(u8)]
113-
#[derive(Debug, PartialEq, FromPrimitive, ToPrimitive, Clone, Copy, serde::Deserialize, serde::Serialize)]
114-
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
115+
#[derive(Debug, PartialEq, FromPrimitive, ToPrimitive, Clone, Copy)]
116+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
117+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
115118
#[non_exhaustive]
116119
pub enum SpiNaplesMicronMode {
117120
DummyCycle = 0x0a,
@@ -163,8 +166,9 @@ impl Setter<EfhRomeSpiMode> for EfhRomeSpiMode {
163166
}
164167

165168
#[repr(u8)]
166-
#[derive(Debug, PartialEq, FromPrimitive, ToPrimitive, Clone, Copy, serde::Deserialize, serde::Serialize)]
167-
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
169+
#[derive(Debug, PartialEq, FromPrimitive, ToPrimitive, Clone, Copy)]
170+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
171+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
168172
#[non_exhaustive]
169173
pub enum SpiRomeMicronMode {
170174
SupportMicron = 0x55,
@@ -243,8 +247,9 @@ impl Default for Efh {
243247
}
244248

245249
#[repr(i8)]
246-
#[derive(Debug, PartialEq, FromPrimitive, Clone, Copy, EnumString, serde::Deserialize, serde::Serialize, strum_macros::EnumIter)]
247-
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
250+
#[derive(Debug, PartialEq, FromPrimitive, Clone, Copy, EnumString, strum_macros::EnumIter)]
251+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
252+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
248253
pub enum ProcessorGeneration {
249254
Naples = -1,
250255
Rome = 0,
@@ -304,8 +309,9 @@ impl Efh {
304309
}
305310
}
306311

307-
#[derive(Debug, PartialEq, Eq, FromPrimitive, Clone, Copy, BitfieldSpecifier, serde::Deserialize, serde::Serialize)]
308-
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
312+
#[derive(Debug, PartialEq, Eq, FromPrimitive, Clone, Copy, BitfieldSpecifier)]
313+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
314+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
309315
pub enum AddressMode {
310316
/// Only supported for images <= 16 MiB.
311317
/// Right-justified in 4 GiB address space.
@@ -459,8 +465,8 @@ macro_rules! make_bitfield_serde {(
459465
}
460466

461467
paste::paste! {
462-
#[derive(serde::Deserialize, serde::Serialize)]
463-
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
468+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
469+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
464470
//#[serde(remote = "" $StructName)]
465471
pub(crate) struct [<Serde $StructName>] {
466472
$(
@@ -635,8 +641,9 @@ impl core::fmt::Debug for PspDirectoryHeader {
635641
}
636642

637643
#[repr(u8)]
638-
#[derive(Debug, PartialEq, FromPrimitive, Clone, Copy, BitfieldSpecifier, serde::Deserialize, serde::Serialize)]
639-
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
644+
#[derive(Debug, PartialEq, FromPrimitive, Clone, Copy, BitfieldSpecifier)]
645+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
646+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
640647
#[bits = 8]
641648
#[non_exhaustive]
642649
pub enum PspDirectoryEntryType {
@@ -727,8 +734,9 @@ impl DummyErrorChecks for PspDirectoryEntryType {
727734
}
728735

729736
/// For 32 MiB SPI Flash, which half to map to MMIO 0xff00_0000.
730-
#[derive(Debug, PartialEq, FromPrimitive, Clone, Copy, BitfieldSpecifier, serde::Deserialize, serde::Serialize)]
731-
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
737+
#[derive(Debug, PartialEq, FromPrimitive, Clone, Copy, BitfieldSpecifier)]
738+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
739+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
732740
#[bits = 1]
733741
pub enum PspSoftFuseChain32MiBSpiDecoding {
734742
LowerHalf = 0,
@@ -738,8 +746,9 @@ pub enum PspSoftFuseChain32MiBSpiDecoding {
738746
impl DummyErrorChecks for PspSoftFuseChain32MiBSpiDecoding {
739747
}
740748

741-
#[derive(Debug, PartialEq, FromPrimitive, Clone, Copy, BitfieldSpecifier, serde::Deserialize, serde::Serialize)]
742-
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
749+
#[derive(Debug, PartialEq, FromPrimitive, Clone, Copy, BitfieldSpecifier)]
750+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
751+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
743752
#[bits = 1]
744753
pub enum PspSoftFuseChainPostCodeDecoding {
745754
Lpc = 0,
@@ -785,8 +794,9 @@ impl Default for PspSoftFuseChain {
785794
}
786795

787796
#[repr(u8)]
788-
#[derive(Debug, PartialEq, FromPrimitive, Clone, Copy, BitfieldSpecifier, serde::Deserialize, serde::Serialize)]
789-
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
797+
#[derive(Debug, PartialEq, FromPrimitive, Clone, Copy, BitfieldSpecifier)]
798+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
799+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
790800
#[bits = 2]
791801
#[non_exhaustive]
792802
pub enum PspDirectoryRomId {
@@ -804,8 +814,9 @@ impl Default for PspDirectoryRomId {
804814
}
805815

806816
#[repr(u8)]
807-
#[derive(Debug, PartialEq, FromPrimitive, Clone, Copy, BitfieldSpecifier, serde::Deserialize, serde::Serialize)]
808-
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
817+
#[derive(Debug, PartialEq, FromPrimitive, Clone, Copy, BitfieldSpecifier)]
818+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
819+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
809820
#[bits = 2]
810821
#[non_exhaustive]
811822
pub enum BhdDirectoryRomId {
@@ -841,14 +852,15 @@ fn zero() -> u8 {
841852
}
842853

843854
#[doc(hidden)]
844-
#[derive(serde::Serialize, serde::Deserialize)]
845-
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
855+
#[cfg(feature = "serde")]
856+
#[derive(serde::Deserialize, serde::Serialize)]
857+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
846858
pub struct CustomSerdePspDirectoryEntryAttrs {
847-
#[serde(rename = "type")]
859+
#[cfg_attr(feature = "serde", serde(rename = "type"))]
848860
pub type_: PspDirectoryEntryType,
849-
#[serde(default = "zero")]
861+
#[cfg_attr(feature = "serde", serde(default = "zero"))]
850862
pub sub_program: u8,
851-
#[serde(default)]
863+
#[cfg_attr(feature = "serde", serde(default))]
852864
pub rom_id: PspDirectoryRomId,
853865
}
854866

@@ -1042,8 +1054,9 @@ impl core::fmt::Debug for BhdDirectoryHeader {
10421054
}
10431055

10441056
#[repr(u8)]
1045-
#[derive(Debug, PartialEq, FromPrimitive, Clone, Copy, BitfieldSpecifier, serde::Deserialize, serde::Serialize)]
1046-
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
1057+
#[derive(Debug, PartialEq, FromPrimitive, Clone, Copy, BitfieldSpecifier)]
1058+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1059+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
10471060
#[bits = 8]
10481061
#[non_exhaustive]
10491062
pub enum BhdDirectoryEntryType {
@@ -1068,8 +1081,9 @@ pub enum BhdDirectoryEntryType {
10681081
impl DummyErrorChecks for BhdDirectoryEntryType {
10691082
}
10701083

1071-
#[derive(Copy, Clone, Debug, FromPrimitive, BitfieldSpecifier, serde::Deserialize, serde::Serialize)]
1072-
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
1084+
#[derive(Copy, Clone, Debug, FromPrimitive, BitfieldSpecifier)]
1085+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1086+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
10731087
#[bits = 8]
10741088
#[non_exhaustive]
10751089
pub enum BhdDirectoryEntryRegionType {
@@ -1133,8 +1147,9 @@ fn sub_program_default() -> u8 {
11331147
}
11341148

11351149
#[doc(hidden)]
1136-
#[derive(serde::Serialize, serde::Deserialize)]
1137-
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
1150+
#[cfg(feature = "serde")]
1151+
#[derive(serde::Deserialize, serde::Serialize)]
1152+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
11381153
pub struct CustomSerdeBhdDirectoryEntryAttrs {
11391154
#[serde(rename = "type")]
11401155
pub type_: BhdDirectoryEntryType,
@@ -1328,8 +1343,9 @@ impl core::fmt::Debug for BhdDirectoryEntry {
13281343
}
13291344

13301345
#[repr(u32)]
1331-
#[derive(Debug, PartialEq, FromPrimitive, ToPrimitive, Clone, Copy, serde::Deserialize, serde::Serialize)]
1332-
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
1346+
#[derive(Debug, PartialEq, FromPrimitive, ToPrimitive, Clone, Copy)]
1347+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1348+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
13331349
#[non_exhaustive]
13341350
pub enum ComboDirectoryLookupMode {
13351351
BruteForce = 0,
@@ -1400,8 +1416,9 @@ impl ComboDirectoryHeader {
14001416
}
14011417

14021418
//#[repr(u8)]
1403-
#[derive(Debug, PartialEq, Eq, Clone, Copy, serde::Deserialize, serde::Serialize, PartialOrd, Ord)]
1404-
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
1419+
#[derive(Debug, PartialEq, Eq, Clone, Copy, PartialOrd, Ord)]
1420+
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
1421+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
14051422
#[non_exhaustive]
14061423
pub enum ComboDirectoryEntryFilter {
14071424
PspId(u32), // = 0,

src/serializers.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Note that if too many fields are private, it means that those are not in the proxy struct in the first place. This might cause problems.
44
// Also, serialization can fail if the nice simple user-visible type cannot represent what we are doing.
55

6+
#![cfg(feature = "serde")]
7+
68
use crate::ondisk::*;
79
use crate::struct_accessors::DummyErrorChecks;
810

@@ -31,7 +33,7 @@ macro_rules! make_serde{($StructName:ident, $SerdeStructName:ident, [$($field_na
3133
}.serialize(serializer)
3234
}
3335
}
34-
#[cfg(feature = "std")]
36+
#[cfg(feature = "schemars")]
3537
impl schemars::JsonSchema for $StructName {
3638
fn schema_name() -> String {
3739
$SerdeStructName::schema_name()

src/struct_accessors.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,12 @@ macro_rules! make_accessors {(
224224
// for serde
225225
paste::paste!{
226226
#[doc(hidden)]
227+
#[cfg(feature = "serde")]
227228
#[derive(serde::Serialize, serde::Deserialize)]
228-
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
229+
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
229230
// Make it possible to just delegate serde entirely to
230231
// this struct instead of $StructName
231-
#[serde(rename = "" $StructName)]
232+
#[cfg_attr(feature = "serde", serde(rename = "" $StructName))]
232233
// Doing remoting automatically would make it impossible for the user to use another one.
233234
// Since the config format presumably needs to be
234235
// backward-compatible, that wouldn't be such a great idea.

0 commit comments

Comments
 (0)