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§
Sourcetype LatestVersion
type LatestVersion
The type for the latest content.
Required Methods§
Sourcefn is_fully_updated(&self) -> bool
fn is_fully_updated(&self) -> bool
Returns true if at the latest version.
Sourcefn in_place_fully_update(&mut self) -> &mut Self
fn in_place_fully_update(&mut self) -> &mut Self
Updates to the latest version in place.
Sourcefn fully_update_and_into_latest_version(self) -> Self::LatestVersion
fn fully_update_and_into_latest_version(self) -> Self::LatestVersion
Updates itself to the latest version, then returns the latest content
Sourcefn from_latest_version(latest: Self::LatestVersion) -> Self
fn from_latest_version(latest: Self::LatestVersion) -> Self
Constructs a versioned wrapper around the latest content
Sourcefn as_latest_version(&self) -> Option<&Self::LatestVersion>
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
].
Sourcefn as_latest_version_mut(&mut self) -> Option<&mut Self::LatestVersion>
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
].
Sourcefn as_versions(&self) -> &Self::Versions
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
.
Sourcefn as_versions_mut(&mut self) -> &mut Self::Versions
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
.
Sourcefn into_versions(self) -> Self::Versions
fn into_versions(self) -> Self::Versions
Removes the upgradable wrapper to get at the inner versions enum, for e.g. matching on the enum.
Sourcefn from_versions(version: Self::Versions) -> Self
fn from_versions(version: Self::Versions) -> Self
Creates a new Versioned wrapper from a given specific version.
Provided Methods§
Sourcefn in_place_fully_update_and_as_latest_version_mut(
&mut self,
) -> &mut Self::LatestVersion
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
Sourcefn fully_update(self) -> Self
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.