Versioned

Trait Versioned 

Source
pub trait Versioned:
    AsRef<Self::Versions>
    + AsMut<Self::Versions>
    + From<Self::Versions> {
    type Versions: From<Self>;
    type LatestVersion;

    // Required methods
    fn is_fully_updated(&self) -> bool;
    fn in_place_fully_update(&mut self) -> &mut Self;
    fn fully_update_and_into_latest_version(self) -> Self::LatestVersion;
    fn from_latest_version(latest: Self::LatestVersion) -> Self;
    fn as_latest_version(&self) -> Option<&Self::LatestVersion>;
    fn as_latest_version_mut(&mut self) -> Option<&mut Self::LatestVersion>;
    fn as_versions(&self) -> &Self::Versions;
    fn as_versions_mut(&mut self) -> &mut Self::Versions;
    fn into_versions(self) -> Self::Versions;
    fn from_versions(version: Self::Versions) -> Self;

    // Provided methods
    fn in_place_fully_update_and_as_latest_version_mut(
        &mut self,
    ) -> &mut Self::LatestVersion { ... }
    fn fully_update(self) -> Self { ... }
}
Expand description

A trait implemented by versioned types created via define_versioned and define_single_versioned.

A versioned type is a type wrapping an enum, this enum is the associated type Versioned::Versions, and contains a variant for each supported version.

This Versioned type itself is a struct wrapper around this enum, which allows for fully updating the contained version to Versioned::LatestVersion. This wrapper is required so that the wrapper can take ownership of old versions as part of the upgrade process, in order to incrementally update them using the From trait.

Required Associated Types§

Source

type Versions: From<Self>

The type for the enum of versions.

Source

type LatestVersion

The type for the latest content.

Required Methods§

Source

fn is_fully_updated(&self) -> bool

Returns true if at the latest version.

Source

fn in_place_fully_update(&mut self) -> &mut Self

Updates to the latest version in place.

Source

fn fully_update_and_into_latest_version(self) -> Self::LatestVersion

Updates itself to the latest version, then returns the latest content

Source

fn from_latest_version(latest: Self::LatestVersion) -> Self

Constructs a versioned wrapper around the latest content

Source

fn as_latest_version(&self) -> Option<&Self::LatestVersion>

If the versioned wrapper is at the latest version, it returns an immutable reference to the latest content, otherwise it returns None.

If you require the latest version unconditionally, consider using [in_place_fully_update_and_as_latest_version_mut] to update to the latest version first - or, if there is only a single version, use [as_unique_version].

Source

fn as_latest_version_mut(&mut self) -> Option<&mut Self::LatestVersion>

If the versioned wrapper is at the latest version, it returns a mutable reference to the latest content, otherwise it returns None.

If you require the latest version unconditionally, consider using [in_place_fully_update_and_as_latest_version_mut] to update to the latest version first - or, if there is only a single version, use [as_unique_version_mut].

Source

fn as_versions(&self) -> &Self::Versions

Gets a reference the inner versions enum, for e.g. matching on the enum.

This is essentially a clearer alias for as_ref.

Source

fn as_versions_mut(&mut self) -> &mut Self::Versions

Gets a mutable reference the inner versions enum, for e.g. matching on the enum.

This is essentially a clearer alias for as_mut.

Source

fn into_versions(self) -> Self::Versions

Removes the upgradable wrapper to get at the inner versions enum, for e.g. matching on the enum.

Source

fn from_versions(version: Self::Versions) -> Self

Creates a new Versioned wrapper from a given specific version.

Provided Methods§

Source

fn in_place_fully_update_and_as_latest_version_mut( &mut self, ) -> &mut Self::LatestVersion

Updates the latest version in place, and returns a &mut to the latest content

Source

fn fully_update(self) -> Self

Consumes self, updates to the latest version and returns itself.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§