[][src]Trait exonum::runtime::versioning::RequireArtifact

pub trait RequireArtifact {
    fn required_artifact() -> ArtifactReq;
}

Versioned object that checks compatibility with the artifact of a service.

Examples

This trait is usually implemented via the derive macro from the exonum_derive crate:

use exonum_derive::*;

#[derive(Debug, FromAccess, RequireArtifact)]
#[require_artifact(name = "some.Service", version = "1")]
pub struct Schema<T: Access> {
    pub wallets: ProofMapIndex<T::Base, str, u64>,
}

assert_eq!(
    Schema::<&'static Fork>::required_artifact(),
    "some.Service@^1".parse().unwrap()
);

Both name and version fields of the require_artifact are have default values:

  • name needs to agree with the artifact name as defined in the service factory for the corresponding service. By default, it is set to the crate name.
  • version is a semantic version requirement. By default, it is set to be semver-compatible with the current version of the crate. For stability, it may make sense to set version when the interface is created and not change it since. For example, a service may set version = "1" in the v1.0.0 release and keep this requirement in the following semver-compatible versions.

If the interface needs to be extended, you may define the extension as a new type with the corresponding bump in version.

#[derive(Debug, FromAccess, RequireArtifact)]
#[require_artifact(name = "some.Service", version = "1.3.0")]
pub struct ExtendedSchema<T: Access> {
    pub wallets: ProofMapIndex<T::Base, str, u64>,
    /// Added in version 1.3.0.
    pub total_token_amount: ProofEntry<T::Base, u64>,
}

Required methods

fn required_artifact() -> ArtifactReq

Returns the artifact requirement.

Loading content...

Implementors

Loading content...