From: Gabriel Goller <g.goller@proxmox.com>
To: Wolfgang Bumiller <w.bumiller@proxmox.com>
Cc: pdm-devel@lists.proxmox.com
Subject: Re: [pdm-devel] [PATCH proxmox 3/3] section-config: add lookup and convert_to_typed_array helpers
Date: Wed, 23 Apr 2025 12:00:13 +0200 [thread overview]
Message-ID: <zu6c4igc376ayqum45s4vwvukwvecf7yv7osumozh3bn5apmoh@2qks7zijdkgh> (raw)
In-Reply-To: <ookoafe5u5cxbrxskvs2cd4372x7iopzhms27kzb5lqkpwry3u@frdpuzgmjmrc>
On 15.04.2025 10:39, Wolfgang Bumiller wrote:
>On Mon, Apr 14, 2025 at 02:00:45PM +0200, Gabriel Goller wrote:
>> [snip]
>> +#[macro_export]
>> +macro_rules! lookup {
>> + ($map:expr, $key:expr, $variant:path) => {
>> + $map.get($key).and_then(|value| {
>> + if let $variant(inner) = value {
>> + Some(inner)
>> + } else {
>> + None
>> + }
>> + })
>
>^ You could shorten this by matching on the nested structure here:
>
> match $map.get($key) {
> Some($variant(inner)) => Some(inner),
> _ => None,
> }
>
Agree, thanks!
>> + };
>> +}
>> +
>> +#[macro_export]
>> +macro_rules! convert_to_typed_array {
>> + ($map:expr, $variant:path) => {
>> + $map.values()
>> + .filter_map(|value| {
>> + if let $variant(inner) = value {
>> + Some(inner)
>> + } else {
>> + None
>> + }
>
>^ (rustfmt puts a `match` here on the `filter_map` line, so that would
>be much shorter ;-) )
Hmm weird, neither fmt nor clippy shows me this :(
Either way, looks cleaner, thanks!
>> + })
>> + .collect::<Vec<_>>()
>> + };
>> +}
>> +
>> +pub use lookup;
>> +pub use convert_to_typed_array;
>
>If, for now, you intend for these to be used via the `typed` module
>instead of at the top level you should mark these re-exports with
>`#[doc(inline)]` and the macros above with `#[doc(hidden)]`.
>
>Otherwise the documentation shows them at the top level, with the ones
>in `typed` as re-exports.
True!
>> [snip]
Thanks for the review.
Will send a v2 soon!
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
next prev parent reply other threads:[~2025-04-23 10:00 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-14 12:00 [pdm-devel] [PATCH proxmox{, -datacenter-manager} 0/4] Remove direct access to SectionConfigData<T> sections Gabriel Goller
2025-04-14 12:00 ` [pdm-devel] [PATCH proxmox 1/3] section-config: make write_section_config parameter more generic Gabriel Goller
2025-04-15 6:44 ` Wolfgang Bumiller
2025-04-23 9:35 ` Gabriel Goller
2025-04-14 12:00 ` [pdm-devel] [PATCH proxmox 2/3] section-config: remove DerefMut and make underlying HashMap private Gabriel Goller
2025-04-15 8:29 ` Wolfgang Bumiller
2025-04-23 9:40 ` Gabriel Goller
2025-04-15 8:42 ` Wolfgang Bumiller
2025-04-23 9:44 ` Gabriel Goller
2025-04-14 12:00 ` [pdm-devel] [PATCH proxmox 3/3] section-config: add lookup and convert_to_typed_array helpers Gabriel Goller
2025-04-15 8:39 ` Wolfgang Bumiller
2025-04-23 10:00 ` Gabriel Goller [this message]
2025-04-14 12:00 ` [pdm-devel] [PATCH proxmox-datacenter-manager 1/1] remotes: remove direct access on underlying sections HashMap Gabriel Goller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=zu6c4igc376ayqum45s4vwvukwvecf7yv7osumozh3bn5apmoh@2qks7zijdkgh \
--to=g.goller@proxmox.com \
--cc=pdm-devel@lists.proxmox.com \
--cc=w.bumiller@proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal