Skip to content

Commit 3c1012c

Browse files
committed
Rename make_serde to impl_struct_serde_conversion (same as in amd-apcb).
1 parent dcadd49 commit 3c1012c

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ strum_macros = { version = "0.23.1" }
2828
zerocopy = "0.6"
2929
thiserror = { version = "1.0.38", optional = true }
3030
memoffset = "0.5"
31-
quote = { version = "1.0.33", default-features = false, features = [] }
3231

3332
[features]
3433
default = []

src/ondisk.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -749,15 +749,17 @@ macro_rules! make_bitfield_serde {(
749749
}
750750
}
751751

752-
// for serde
753752
#[cfg(feature = "serde")]
754753
paste::paste!{
754+
/// Use this for serialization in order to make serde skip those fields
755+
/// where the meaning of a raw value is unknown to us.
756+
///
757+
/// Caller can then override Serializer::skip_field and thus find out
758+
/// which fields were skipped, inferring where errors were.
755759
#[doc(hidden)]
756760
#[allow(non_camel_case_types)]
757761
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
758-
//#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
759762
#[cfg_attr(feature = "serde", serde(rename = "" $StructName))]
760-
//#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
761763
pub(crate) struct [<SerdePermissiveSerializing $StructName>] {
762764
$(
763765
$(#[serde(skip_serializing_if="Option::is_none")] pub $field_name: Option<$field_ty>,)?

src/serializers.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
#![cfg(feature = "serde")]
77

88
use crate::ondisk::*;
9-
//use quote::quote;
109

1110
// Note: This is written such that it will fail if the underlying struct has fields added/removed/renamed--if those have a public setter.
12-
macro_rules! make_serde{($StructName:ident, $SerdeStructName:ident, $SerializingStructName:ident, [$($field_name:ident),* $(,)?]
11+
macro_rules! impl_struct_serde_conversion{($StructName:ident, $SerdeStructName:ident, $SerializingStructName:ident, [$($field_name:ident),* $(,)?]
1312
) => (
1413
paste::paste!{
1514
#[cfg(feature = "serde")]
@@ -49,13 +48,13 @@ macro_rules! make_serde{($StructName:ident, $SerdeStructName:ident, $Serializing
4948
}
5049
)}
5150

52-
make_serde!(
51+
impl_struct_serde_conversion!(
5352
DirectoryAdditionalInfo,
5453
SerdeDirectoryAdditionalInfo,
5554
SerdePermissiveSerializingDirectoryAdditionalInfo,
5655
[max_size, spi_block_size, base_address, address_mode, _reserved_0,]
5756
);
58-
make_serde!(
57+
impl_struct_serde_conversion!(
5958
PspSoftFuseChain,
6059
SerdePspSoftFuseChain,
6160
SerdePermissiveSerializingPspSoftFuseChain,

src/struct_accessors.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,16 +311,23 @@ macro_rules! make_accessors {(
311311
)?
312312
)*
313313
}
314-
// for serde
315314
#[cfg(feature = "serde")]
316315
paste::paste!{
316+
/// Use this for serialization in order to make serde skip those fields
317+
/// where the meaning of a raw value is unknown to us.
318+
///
319+
/// Caller can then override Serializer::skip_field and thus find out
320+
/// which fields were skipped, inferring where errors were.
317321
#[doc(hidden)]
318322
#[allow(non_camel_case_types)]
319323
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
320324
//#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
321325
#[cfg_attr(feature = "serde", serde(rename = "" $StructName))]
322326
//#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
323327
// Rust's serde automatically has Options transparent--but not Results.
328+
// See also <https://github.com/serde-rs/serde/issues/1042> for
329+
// limitations (that don't hit us since our zerocopy structs
330+
// can't have Option<Option<T>> anyway).
324331
pub(crate) struct [<SerdePermissiveSerializing $StructName>] {
325332
$(
326333
$(#[serde(skip_serializing_if="Option::is_none")] pub $field_name: Option<$field_ty>,)?

0 commit comments

Comments
 (0)