public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox Backup Server development discussion
	<pbs-devel@lists.proxmox.com>,
	Wolfgang Bumiller <w.bumiller@proxmox.com>
Subject: Re: [pbs-devel] [PATCH proxmox] schema: add const fn unwrap_*_schema/format methods
Date: Wed, 23 Feb 2022 09:31:03 +0100	[thread overview]
Message-ID: <5c043fdd-de17-f54e-c117-c0d51471d16a@proxmox.com> (raw)
In-Reply-To: <20220222084717.60064-1-w.bumiller@proxmox.com>

On 22.02.22 09:47, Wolfgang Bumiller wrote:
> 'unwrap_' because they will panic and as `const fn` since
> panic in const fn is now possible
> 
> Note that const evaluation will only be triggered when
> actually used in const context, so to ensure *compile time*
> checks, use something like this:
> 
>     const FOO_SCHEMA: &AllOfSchema =
>         SomeType::API_SCHEMA.unwrap_all_of_schema();
>     then_use(FOO_SCHEMA);
> 
> or to use the list of enum values of an enum string type
> with compile time checks:
> 
>     const LIST: &'static [EnumEntry] =
>         AnEnumStringType::API_SCHEMA
>             .unwrap_string_schema()
>             .unwrap_format()
>             .unwrap_enum_format();
>     for values in LIST {
>         ...
>     }
> 
> Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
> ---
> While schemas are usually unlikely to change type or lose properties
> such as enum lists, for `ObjectSchema` and `AllOfSchema` this may
> actually allow catching future issues at build-time...
> 
> If we want to do this, I'd prepare a similar patch set for all the
> `ApiHandler::...` value extractions we do in the CLI in pbs (just look
> at the output of `egrep -B1 -nr 'unreachable' ./src ./*/src` in pbs ;-) )
> 

IMO the usage gets nicer, lots of removal of unreachable!(), and even if
not used correctly (without const) we're as good as now; so can only win.

If there's no objection from others I'd say: go for it.




      parent reply	other threads:[~2022-02-23  8:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-22  8:47 Wolfgang Bumiller
2022-02-22  8:47 ` [pbs-devel] [PATCH backup] constify schema usage and dedup some code Wolfgang Bumiller
2022-02-23  8:31 ` Thomas Lamprecht [this message]

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=5c043fdd-de17-f54e-c117-c0d51471d16a@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=pbs-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