Skip to content

Commit 2c5d73c

Browse files
hampuslidinJoshua Wademaan2003
authored
Add missing derived lens documentation (#1696)
* Add missing derived lens documentation * Update CHANGELOG.md * Update link references in CHANGELOG.md * Update derived lens documentation Co-authored-by: Manmeet Maan <49202620+Maan2003@users.noreply.github.com> * Improve code readability Co-authored-by: Joshua Wade <SecondFlight@users.noreply.github.com> Co-authored-by: Manmeet Maan <49202620+Maan2003@users.noreply.github.com>
1 parent 46c6414 commit 2c5d73c

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ You can find its changes [documented below](#070---2021-01-01).
3030
- `Notification`s can be submitted while handling other `Notification`s ([#1640] by [@cmyr])
3131
- Added ListIter implementations for OrdMap ([#1641] by [@Lejero])
3232
- `Padding` can now use `Key<Insets>` ([#1662] by [@cmyr])
33+
- Added missing documentation on derived lens items ([#1696] by [@lidin])
3334
- `LifeCycle::DisabledChanged`, `InternalLifeCycle::RouteDisabledChanged` and the `set_disabled()` and `is_disabled()`
3435
context-methods to implement disabled ([#1632] by [@xarvic])
3536
- `LifeCycle::BuildFocusChain` to update the focus-chain ([#1632] by [@xarvic])
@@ -450,6 +451,7 @@ Last release without a changelog :(
450451
[@SecondFlight]: https://github.com/SecondFlight
451452
[@lord]: https://github.com/lord
452453
[@Lejero]: https://github.com/Lejero
454+
[@lidin]: https://github.com/lidin
453455
[@xarvic]: https://github.com/xarvic
454456
[@arthmis]: https://github.com/arthmis
455457
[@ccqpein]: https://github.com/ccqpein
@@ -672,6 +674,7 @@ Last release without a changelog :(
672674
[#1677]: https://github.com/linebender/druid/pull/1677
673675
[#1691]: https://github.com/linebender/druid/pull/1691
674676
[#1693]: https://github.com/linebender/druid/pull/1693
677+
[#1696]: https://github.com/linebender/druid/pull/1696
675678
[#1698]: https://github.com/linebender/druid/pull/1698
676679
[#1695]: https://github.com/linebender/druid/pull/1695
677680

druid-derive/src/lens.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,27 @@ fn derive_struct(input: &syn::DeriveInput) -> Result<proc_macro2::TokenStream, s
8383
// Define lens types for each field
8484
let defs = fields.iter().filter(|f| !f.attrs.ignore).map(|f| {
8585
let field_name = &f.ident.unwrap_named();
86-
let docs = format!(
87-
"Lens for the field `{}` on [`{1}`](super::{1})",
88-
field_name, ty
86+
let struct_docs = format!(
87+
"Lens for the field `{field}` on [`{ty}`](super::{ty}).",
88+
field = field_name,
89+
ty = ty,
90+
);
91+
92+
let fn_docs = format!(
93+
"Creates a new lens for the field `{field}` on [`{ty}`](super::{ty}). \
94+
Use [`{ty}::{field}`](super::{ty}::{field}) instead.",
95+
field = field_name,
96+
ty = ty,
8997
);
9098

9199
quote! {
92-
#[doc = #docs]
100+
#[doc = #struct_docs]
93101
#[allow(non_camel_case_types)]
94102
#[derive(Debug, Copy, Clone)]
95103
pub struct #field_name#lens_ty_generics(#(#phantom_decls),*);
96104

97105
impl #lens_ty_generics #field_name#lens_ty_generics{
106+
#[doc = #fn_docs]
98107
pub const fn new()->Self{
99108
Self(#(#phantom_inits),*)
100109
}
@@ -148,12 +157,15 @@ fn derive_struct(input: &syn::DeriveInput) -> Result<proc_macro2::TokenStream, s
148157
let lens_field_name = f.attrs.lens_name_override.as_ref().unwrap_or(&field_name);
149158

150159
quote! {
151-
/// Lens for the corresponding field
160+
/// Lens for the corresponding field.
152161
pub const #lens_field_name: #twizzled_name::#field_name#lens_ty_generics = #twizzled_name::#field_name::new();
153162
}
154163
});
155164

165+
let mod_docs = format!("Derived lenses for [`{}`].", ty);
166+
156167
let expanded = quote! {
168+
#[doc = #mod_docs]
157169
pub mod #twizzled_name {
158170
#(#defs)*
159171
}

0 commit comments

Comments
 (0)