Skip to content

Commit

Permalink
Merge pull request #2714 from Marcono1234/skipped-field-struct-len
Browse files Browse the repository at this point in the history
Document that `len` does not include skipped struct fields
  • Loading branch information
dtolnay committed Mar 16, 2024
2 parents 3f43fca + eae7c2d commit 9f8c579
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion serde/src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,8 @@ pub trait Serializer: Sized {
/// then a call to `end`.
///
/// The `name` is the name of the struct and the `len` is the number of
/// data fields that will be serialized.
/// data fields that will be serialized. `len` does not include fields
/// which are skipped with [`SerializeStruct::skip_field`].
///
/// ```edition2021
/// use serde::ser::{Serialize, SerializeStruct, Serializer};
Expand Down Expand Up @@ -1207,6 +1208,8 @@ pub trait Serializer: Sized {
/// The `name` is the name of the enum, the `variant_index` is the index of
/// this variant within the enum, the `variant` is the name of the variant,
/// and the `len` is the number of data fields that will be serialized.
/// `len` does not include fields which are skipped with
/// [`SerializeStructVariant::skip_field`].
///
/// ```edition2021
/// use serde::ser::{Serialize, SerializeStructVariant, Serializer};
Expand Down Expand Up @@ -1857,6 +1860,8 @@ pub trait SerializeStruct {
T: ?Sized + Serialize;

/// Indicate that a struct field has been skipped.
///
/// The default implementation does nothing.
#[inline]
fn skip_field(&mut self, key: &'static str) -> Result<(), Self::Error> {
let _ = key;
Expand Down Expand Up @@ -1919,6 +1924,8 @@ pub trait SerializeStructVariant {
T: ?Sized + Serialize;

/// Indicate that a struct variant field has been skipped.
///
/// The default implementation does nothing.
#[inline]
fn skip_field(&mut self, key: &'static str) -> Result<(), Self::Error> {
let _ = key;
Expand Down

0 comments on commit 9f8c579

Please sign in to comment.