Skip to content

Commit 4dce3ee

Browse files
committed
Switch to using serde(borrow)
1 parent e495e1e commit 4dce3ee

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/lib.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -318,17 +318,6 @@ pub const fn hash_type_graph<T: TypeGraphLayout>(seed: u64) -> u64 {
318318
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
319319
#[cfg_attr(feature = "serde", allow(clippy::unsafe_derive_deserialize))]
320320
#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
321-
#[cfg_attr(
322-
feature = "serde",
323-
serde(bound(serialize = "F: ::serde::Serialize, V: ::serde::Serialize, I: \
324-
::serde::Serialize, G: ::serde::Serialize"))
325-
)]
326-
#[cfg_attr(
327-
feature = "serde",
328-
serde(bound(deserialize = "'a: 'de, F: ::serde::Deserialize<'a>, V: \
329-
::serde::Deserialize<'a>, I: ::serde::Deserialize<'a>, G: \
330-
::serde::Deserialize<'a>"))
331-
)]
332321
/// Description of the deep layout of a type.
333322
pub struct TypeLayoutGraph<
334323
'a,
@@ -338,6 +327,7 @@ pub struct TypeLayoutGraph<
338327
G: Deref<Target = [I]> = &'a [I],
339328
> {
340329
/// The type's fully-qualified name.
330+
#[cfg_attr(feature = "serde", serde(borrow))]
341331
pub ty: &'a str,
342332
/// The list of types that make up the complete graph describing the deep
343333
/// layout of this type.
@@ -353,12 +343,14 @@ pub struct TypeLayoutInfo<
353343
V: Deref<Target = [Variant<'a, F>]> = &'a [Variant<'a, F>],
354344
> {
355345
/// The type's fully-qualified name.
346+
#[cfg_attr(feature = "serde", serde(borrow))]
356347
pub name: &'a str,
357348
/// The type's size.
358349
pub size: usize,
359350
/// The type's minimum alignment.
360351
pub alignment: usize,
361352
/// The type's shallow structure.
353+
#[cfg_attr(feature = "serde", serde(borrow))]
362354
pub structure: TypeStructure<'a, F, V>,
363355
}
364356

@@ -377,20 +369,23 @@ pub enum TypeStructure<
377369
/// tuples.
378370
Struct {
379371
/// The string representation of the type's `#[repr(...)]` attributes.
372+
#[cfg_attr(feature = "serde", serde(borrow))]
380373
repr: &'a str,
381374
/// The fields of the struct.
382375
fields: F,
383376
},
384377
/// A union type.
385378
Union {
386379
/// The string representation of the type's `#[repr(...)]` attributes.
380+
#[cfg_attr(feature = "serde", serde(borrow))]
387381
repr: &'a str,
388382
/// The fields of the union.
389383
fields: F,
390384
},
391385
/// An enum type.
392386
Enum {
393387
/// The string representation of the type's `#[repr(...)]` attributes.
388+
#[cfg_attr(feature = "serde", serde(borrow))]
394389
repr: &'a str,
395390
/// The variants of the union.
396391
variants: V,
@@ -402,6 +397,7 @@ pub enum TypeStructure<
402397
/// Description of the shallow layout of a variant
403398
pub struct Variant<'a, F: Deref<Target = [Field<'a>]> = &'a [Field<'a>]> {
404399
/// The variant's name.
400+
#[cfg_attr(feature = "serde", serde(borrow))]
405401
pub name: &'a str,
406402
/// The variant's descriminant, iff the variant is
407403
/// [inhabited](https://doc.rust-lang.org/reference/glossary.html#inhabited).
@@ -585,13 +581,15 @@ impl_extract_discriminant! {
585581
/// Descriptor of the shallow layout of a field.
586582
pub struct Field<'a> {
587583
/// The field's name.
584+
#[cfg_attr(feature = "serde", serde(borrow))]
588585
pub name: &'a str,
589586
/// The field's byte offset, iff the field is
590587
/// [inhabited](https://doc.rust-lang.org/reference/glossary.html#inhabited).
591588
pub offset: MaybeUninhabited<usize>,
592589
/// The fully-qualified name of the field's type. This is used as a key
593590
/// inside [`TypeLayoutGraph::tys`] to find the field's type's layout by
594591
/// its [`TypeLayoutInfo::name`].
592+
#[cfg_attr(feature = "serde", serde(borrow))]
595593
pub ty: &'a str,
596594
}
597595

0 commit comments

Comments
 (0)