From 12b209ad49aef1f2d7aaf12667f7ea57de7efd56 Mon Sep 17 00:00:00 2001 From: bytedream Date: Tue, 2 Sep 2025 14:06:37 +0200 Subject: [PATCH] docs: update code documentation --- src/expand.rs | 10 +++++++--- src/lib.rs | 11 +++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/expand.rs b/src/expand.rs index 496dc8b..c1bab27 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -14,15 +14,19 @@ pub(crate) fn expand_struct(mut item: ItemStruct) -> proc_macro::TokenStream { let default: TokenStream = attr.parse_args().unwrap(); - // copy all the same #[cfg] conditional compilations flags for the field onto our built "constructor" - // otherwise, it's possible to create a constructor for a type that may be filtered by the same #[cfg]'s, breaking compilation + // copy all the same #[cfg] conditional compilations flags for the field onto our built + // default function. + // otherwise, it's possible to create a constructor for a type that may be filtered by + // the same #[cfg]'s, breaking compilation let cfg_attrs = field.attrs.iter().filter(|a| a.path().is_ident("cfg")); let fn_name_lit = format!("__serde_inline_default_{}_{}", item.ident, i); let fn_name_ident = Ident::new(&fn_name_lit, Span::call_site()); let mut return_type = field.ty.clone(); - // replaces most lifetimes with 'static + // replace lifetimes with 'static. + // the built default function / default values in general can only be static as they're + // generated without reference to the parent struct type_lifetimes_to_static(&mut return_type); inline_fns.push(quote! { diff --git a/src/lib.rs b/src/lib.rs index 2701159..1c09256 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,12 +8,15 @@ mod utils; /// The main macro of this crate. /// Use it to define default values of fields in structs you [`Serialize`] or [`Deserialize`]. -/// You do not need to create a extra function to provide the default value, as it is the case in serdes' implementation of default (`#[serde(default = "...")]`). +/// You do not need to create an extra function to provide the default value, as it is the case in +/// serdes' implementation of default (`#[serde(default = "...")]`). /// -/// Set this macro on a struct where you use [`Serialize`] or [`Deserialize`] and use `#[serde_inline_default(...)]` on the field you want to have a inline default value. -/// Replace the `...` with the value you want and it will be set as default if serde needs it. +/// Set this macro on a struct where you use [`Serialize`] or [`Deserialize`] and use +/// `#[serde_inline_default(...)]` on the field you want to have an inline default value. +/// Replace the `...` with the value you want, and it will be set as default if serde needs it. /// -/// Note that you must set this macro _before_ `#[derive(Serialize)]` / `#[derive(Deserialize)]` as it wouldn't work properly if set after the derive. +/// Note that you must set this macro _before_ `#[derive(Serialize)]` / `#[derive(Deserialize)]` as +/// it won't work properly if it's set after the derive. /// /// # Examples ///