pub struct Generation(/* private fields */);Expand description
Generation numbers stored in the database, used for optimistic concurrency control
Generation numbers are monotonic counters: each successive version of a resource is assigned a generation number greater than the one before it.
Implementations§
Source§impl Generation
impl Generation
Sourcepub const ZERO: Generation
pub const ZERO: Generation
The generation number before any change has been applied, 0.
Generation numbers conventionally start at 1 (see Self::new). Zero is
reserved to represent an initial or empty state that precedes the first
generation.
Sourcepub const MAX: Generation
pub const MAX: Generation
The largest possible generation number, 2**63 - 1.
Sourcepub const fn new() -> Generation
pub const fn new() -> Generation
Creates the first generation number, which is 1.
There is deliberately no Default impl: whether a value should start at
Self::ZERO or at the first generation is a choice callers must make
explicitly.
Sourcepub const fn from_u32(value: u32) -> Generation
pub const fn from_u32(value: u32) -> Generation
Creates a generation number from a u32.
Every u32 is a valid generation number, so this conversion is infallible.
Sourcepub const fn next(&self) -> Generation
pub const fn next(&self) -> Generation
Returns the next generation number.
§Panics
Panics if the next generation number would exceed Generation::MAX. Use
Self::checked_next to handle overflow instead.
Sourcepub const fn checked_next(&self) -> Option<Generation>
pub const fn checked_next(&self) -> Option<Generation>
Returns the next generation number, or None if it would exceed Generation::MAX.
Sourcepub const fn prev(&self) -> Option<Generation>
pub const fn prev(&self) -> Option<Generation>
Returns the previous generation number, or None if this is the first generation.
Both 1 and Self::ZERO are treated as having no predecessor: prev never
returns Self::ZERO.
Trait Implementations§
Source§impl Arbitrary for Generation
Available on crate feature proptest1 only.Generates random Generation instances.
impl Arbitrary for Generation
proptest1 only.Generates random Generation instances.
Values are drawn uniformly from the range 0..=Generation::MAX.
Source§type Parameters = GenerationParams
type Parameters = GenerationParams
arbitrary_with accepts for configuration
of the generated Strategy. Parameters must implement Default.Source§type Strategy = BoxedStrategy<Generation>
type Strategy = BoxedStrategy<Generation>
Strategy used to generate values of type Self.Source§fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
Source§impl Clone for Generation
impl Clone for Generation
Source§fn clone(&self) -> Generation
fn clone(&self) -> Generation
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for Generation
Source§impl Debug for Generation
impl Debug for Generation
Source§impl<'de> Deserialize<'de> for Generation
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Generation
serde only.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>,
Source§impl Diffable for Generation
Available on crate feature daft01 only.Diffs a Generation as a leaf value.
impl Diffable for Generation
daft01 only.Diffs a Generation as a leaf value.
Generation numbers are scalars, so diffing stops at them.
Source§impl Display for Generation
impl Display for Generation
impl Eq for Generation
Source§impl From<&Generation> for i64
impl From<&Generation> for i64
Source§fn from(g: &Generation) -> Self
fn from(g: &Generation) -> Self
Source§impl From<Generation> for u64
impl From<Generation> for u64
Source§fn from(g: Generation) -> Self
fn from(g: Generation) -> Self
Source§impl From<Generation> for i64
impl From<Generation> for i64
Source§fn from(g: Generation) -> Self
fn from(g: Generation) -> Self
Source§impl From<u32> for Generation
impl From<u32> for Generation
Source§impl FromStr for Generation
impl FromStr for Generation
Source§impl GenericGeneration for Generation
impl GenericGeneration for Generation
Source§fn from_untyped_generation(generation: Generation) -> Self
fn from_untyped_generation(generation: Generation) -> Self
Self from an untyped Generation.Source§fn into_untyped_generation(self) -> Generation
fn into_untyped_generation(self) -> Generation
self into an untyped Generation.Source§fn as_untyped_generation(&self) -> &Generation
fn as_untyped_generation(&self) -> &Generation
Generation. Read moreSource§impl Hash for Generation
impl Hash for Generation
Source§impl JsonSchema for Generation
Available on crate feature schemars08 only.Implements JsonSchema for Generation.
impl JsonSchema for Generation
schemars08 only.Implements JsonSchema for Generation.
The schema is that of a u64 with a minimum of 0; the upper bound is not expressed in the
schema. The description matches the first line of the doc comment on Generation.
Source§fn schema_name() -> String
fn schema_name() -> String
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(_: &mut SchemaGenerator) -> Schema
fn json_schema(_: &mut SchemaGenerator) -> Schema
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref keyword. Read moreSource§impl Ord for Generation
impl Ord for Generation
Source§fn cmp(&self, other: &Generation) -> Ordering
fn cmp(&self, other: &Generation) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for Generation
impl PartialEq for Generation
Source§impl PartialOrd for Generation
impl PartialOrd for Generation
Source§impl Serialize for Generation
Available on crate feature serde only.
impl Serialize for Generation
serde only.