Skip to content

Commit 12b209a

Browse files
committed
docs: update code documentation
1 parent 8cac0af commit 12b209a

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/expand.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@ pub(crate) fn expand_struct(mut item: ItemStruct) -> proc_macro::TokenStream {
1414

1515
let default: TokenStream = attr.parse_args().unwrap();
1616

17-
// copy all the same #[cfg] conditional compilations flags for the field onto our built "constructor"
18-
// otherwise, it's possible to create a constructor for a type that may be filtered by the same #[cfg]'s, breaking compilation
17+
// copy all the same #[cfg] conditional compilations flags for the field onto our built
18+
// default function.
19+
// otherwise, it's possible to create a constructor for a type that may be filtered by
20+
// the same #[cfg]'s, breaking compilation
1921
let cfg_attrs = field.attrs.iter().filter(|a| a.path().is_ident("cfg"));
2022

2123
let fn_name_lit = format!("__serde_inline_default_{}_{}", item.ident, i);
2224
let fn_name_ident = Ident::new(&fn_name_lit, Span::call_site());
2325
let mut return_type = field.ty.clone();
2426

25-
// replaces most lifetimes with 'static
27+
// replace lifetimes with 'static.
28+
// the built default function / default values in general can only be static as they're
29+
// generated without reference to the parent struct
2630
type_lifetimes_to_static(&mut return_type);
2731

2832
inline_fns.push(quote! {

src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ mod utils;
88

99
/// The main macro of this crate.
1010
/// Use it to define default values of fields in structs you [`Serialize`] or [`Deserialize`].
11-
/// 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 = "...")]`).
11+
/// You do not need to create an extra function to provide the default value, as it is the case in
12+
/// serdes' implementation of default (`#[serde(default = "...")]`).
1213
///
13-
/// 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.
14-
/// Replace the `...` with the value you want and it will be set as default if serde needs it.
14+
/// Set this macro on a struct where you use [`Serialize`] or [`Deserialize`] and use
15+
/// `#[serde_inline_default(...)]` on the field you want to have an inline default value.
16+
/// Replace the `...` with the value you want, and it will be set as default if serde needs it.
1517
///
16-
/// Note that you must set this macro _before_ `#[derive(Serialize)]` / `#[derive(Deserialize)]` as it wouldn't work properly if set after the derive.
18+
/// Note that you must set this macro _before_ `#[derive(Serialize)]` / `#[derive(Deserialize)]` as
19+
/// it won't work properly if it's set after the derive.
1720
///
1821
/// # Examples
1922
///

0 commit comments

Comments
 (0)