Go to file
Thomas Lamprecht 7d34e6f3a4 api macro: reuse generated default const for "unwrap_or"
Instead of setting a default value to a const and inside an
.unwrap_or_else closure, lets set it only to the const and reuse that
later in .unwrap_or

To achieve that we move the "unrwap_or" code for param plumbing code generation
a bit later so that we have easy access to the generated const name.
As all this code is related to optional/default-value stuff it does read still
relatively OK with that change, IMO.

This has the advantage of not getting a warning like:

>  warning: constant is never used: `API_METHOD_EXAMPLE_FOO_PARAM_DEFAULT_FORCE`
>   --> src/api2/node/foo.rs
>    |
> XY |             force: {
>    |             ^^^^^
>    = note: `#[warn(dead_code)]` on by default

When one has a API endpoint like:

> #[api(
>     input: {
>         properties: {
>             force: {
>                 type: bool,
>                 optional: true,
>                 default: false,
>             },
>         },
>     },
>     ...
> )]
> /// Example
> fn example_foo(force: bool) -> Result<(), Error> {
>     if force {
>         // do something
>     }
>     Ok(())
> }

It effectively changes the output for optional parameters with a default set
and no Option<T> from

> let p = p.unwrap_or_else(|| #default_value);

to

> let p = p.unwrap_or(#const_name_for_default);

where the "#const_name_for_default" is a pub const with value
"#default_value"

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-10-27 09:17:12 +01:00
.cargo cargo: switch to use packaged crates by default 2020-01-03 09:39:52 +01:00
proxmox tools fs: fix comment typo and strange glyph 2020-10-20 18:46:50 +02:00
proxmox-api-macro api macro: reuse generated default const for "unwrap_or" 2020-10-27 09:17:12 +01:00
proxmox-sortable-macro bump proxmox-sortable-macro to 0.1.1 2020-04-17 18:37:46 +02:00
.gitignore add Cargo.lock to .gitignore 2020-01-15 17:10:13 +01:00
build.sh build.sh: point to system compiler via rust-toolchain 2020-01-15 16:25:14 +01:00
Cargo.toml merge api, sys and tools into proxmox directly 2020-01-21 12:15:42 +01:00
Makefile buildsys: drop format check in check target 2020-03-16 12:21:14 +01:00
README.rst README: Remove 'Versioning', add 'Steps for Releases' 2020-01-15 14:26:06 +01:00
rustfmt.toml initial import, starting with vec & io helpers 2019-06-06 14:00:25 +02:00

Local cargo config
==================

This repository ships with a ``.cargo/config`` that replaces the crates.io
registry with packaged crates located in ``/usr/share/cargo/registry``.

A similar config is also applied building with dh_cargo. Cargo.lock needs to be
deleted when switching between packaged crates and crates.io, since the
checksums are not compatible.

To reference new dependencies (or updated versions) that are not yet packaged,
the dependency needs to point directly to a path or git source.

Steps for Releases
==================

- Cargo.toml updates:
  - Bump all modified crate versions.
  - Update all the other crates' Cargo.toml to depend on the new versions if
    required, then bump their version as well if not already done.
- Update debian/changelog files in all the crates updated above.
- Build packages with `make deb`.