api_versions

Macro api_versions 

Source
macro_rules! api_versions {
    (
        [
            (
                $latest_major:literal,
                $latest_name: ident
            )
            $(,
                (
                    $major:literal,
                    $name:ident
                )
            )*
            $(,)?
        ] ) => { ... };
}
Expand description

Helper macro used to define API versions.

use dropshot_api_manager_types::{
    SupportedVersion, SupportedVersions, api_versions,
};

api_versions!([
    // Define the API versions here. They must be in descending order.
    (2, ADD_FOOBAR_OPERATION),
    (1, INITIAL),
]);

This example says that there are two API versions: 1.0.0 (the initial version) and 2.0.0 (which adds an operation called “foobar”). This macro invocation defines symbolic constants of type semver::Version for each of these, equivalent to:

pub const VERSION_ADD_FOOBAR_OPERATION: semver::Version =
    semver::Version::new(2, 0, 0);
pub const VERSION_INITIAL: semver::Version = semver::Version::new(1, 0, 0);

It also defines two functions:

  • pub fn supported_versions() -> SupportedVersions that, as the name suggests, returns a SupportedVersions that describes these two supported API versions.

  • pub fn latest_version() -> semver::Version that returns the latest supported API version. The latest supported version is the first version in the list (hence versions must be in descending order).