pub struct Version(/* private fields */);Expand description
Value Object: Version
Represents a version number for entities like events, schemas, or projections.
Domain Rules:
- Must be a positive integer (>= 1)
- Immutable once created
- Sequential within a stream
This is a Value Object:
- Defined by its value, not identity
- Immutable
- Self-validating
- Compared by value equality
Implementations§
Source§impl Version
impl Version
Sourcepub fn first() -> Self
pub fn first() -> Self
Create the first version
§Examples
use allsource_core::domain::value_objects::Version;
let version = Version::first();
assert_eq!(version.as_u64(), 1);
assert!(version.is_first());Sourcepub fn is_first(&self) -> bool
pub fn is_first(&self) -> bool
Check if this is the first version
§Examples
use allsource_core::domain::value_objects::Version;
let v1 = Version::first();
let v2 = Version::new(2).unwrap();
assert!(v1.is_first());
assert!(!v2.is_first());Sourcepub fn next(&self) -> Self
pub fn next(&self) -> Self
Get the next version
§Examples
use allsource_core::domain::value_objects::Version;
let v1 = Version::first();
let v2 = v1.next();
assert_eq!(v2.as_u64(), 2);Sourcepub fn previous(&self) -> Option<Self>
pub fn previous(&self) -> Option<Self>
Get the previous version, if possible
Returns None if this is the first version.
§Examples
use allsource_core::domain::value_objects::Version;
let v2 = Version::new(2).unwrap();
let v1 = v2.previous();
assert_eq!(v1, Some(Version::first()));
let first = Version::first();
assert_eq!(first.previous(), None);Sourcepub fn is_immediately_after(&self, other: &Version) -> bool
pub fn is_immediately_after(&self, other: &Version) -> bool
Check if this version is immediately after another
§Examples
use allsource_core::domain::value_objects::Version;
let v1 = Version::first();
let v2 = Version::new(2).unwrap();
let v3 = Version::new(3).unwrap();
assert!(v2.is_immediately_after(&v1));
assert!(!v3.is_immediately_after(&v1));Trait Implementations§
Source§impl<'de> Deserialize<'de> for Version
impl<'de> Deserialize<'de> for Version
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for Version
impl Ord for Version
Source§impl PartialOrd for Version
impl PartialOrd for Version
impl Copy for Version
impl Eq for Version
impl StructuralPartialEq for Version
Auto Trait Implementations§
impl Freeze for Version
impl RefUnwindSafe for Version
impl Send for Version
impl Sync for Version
impl Unpin for Version
impl UnwindSafe for Version
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.