[pdm-devel] [PATCH proxmox 3/3] section-config: add lookup and convert_to_typed_array helpers
Gabriel Goller
g.goller at proxmox.com
Wed Apr 23 12:00:13 CEST 2025
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!
More information about the pdm-devel
mailing list