Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ You can find its changes [documented below](#070---2021-01-01).
- `Notification`s can be submitted while handling other `Notification`s ([#1640] by [@cmyr])
- Added ListIter implementations for OrdMap ([#1641] by [@Lejero])
- `Padding` can now use `Key<Insets>` ([#1662] by [@cmyr])
- Added missing documentation on derived lens items ([#1696] by [@lidin])

### Changed

Expand Down Expand Up @@ -443,6 +444,7 @@ Last release without a changelog :(
[@SecondFlight]: https://github.com/SecondFlight
[@lord]: https://github.com/lord
[@Lejero]: https://github.com/Lejero
[@lidin]: https://github.com/lidin
[@ccqpein]: https://github.com/ccqpein

[#599]: https://github.com/linebender/druid/pull/599
Expand Down Expand Up @@ -660,6 +662,7 @@ Last release without a changelog :(
[#1660]: https://github.com/linebender/druid/pull/1660
[#1662]: https://github.com/linebender/druid/pull/1662
[#1677]: https://github.com/linebender/druid/pull/1677
[#1696]: https://github.com/linebender/druid/pull/1696
[#1698]: https://github.com/linebender/druid/pull/1698

[Unreleased]: https://github.com/linebender/druid/compare/v0.7.0...master
Expand Down
17 changes: 13 additions & 4 deletions druid-derive/src/lens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,24 @@ fn derive_struct(input: &syn::DeriveInput) -> Result<proc_macro2::TokenStream, s
// Define lens types for each field
let defs = fields.iter().filter(|f| !f.attrs.ignore).map(|f| {
let field_name = &f.ident.unwrap_named();
let docs = format!(
"Lens for the field `{}` on [`{1}`](super::{1})",
let struct_docs = format!(
"Lens for the field `{}` on [`{1}`](super::{1}).",
field_name, ty
);

let fn_docs = format!(
"Creates a new lens for the field `{}` on [`{1}`](super::{1}).",
field_name, ty
);

quote! {
#[doc = #docs]
#[doc = #struct_docs]
#[allow(non_camel_case_types)]
#[derive(Debug, Copy, Clone)]
pub struct #field_name#lens_ty_generics(#(#phantom_decls),*);

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

quote! {
/// Lens for the corresponding field
/// Lens for the corresponding field.
pub const #lens_field_name: #twizzled_name::#field_name#lens_ty_generics = #twizzled_name::#field_name::new();
}
});

let mod_docs = format!("Derived lenses for [`{}`].", ty);

let expanded = quote! {
#[doc = #mod_docs]
pub mod #twizzled_name {
#(#defs)*
}
Expand Down