Skip to main content

Generation

Struct Generation 

Source
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

Source

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.

Source

pub const MAX: Generation

The largest possible generation number, 2**63 - 1.

Source

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.

Source

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.

Source

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.

Source

pub const fn checked_next(&self) -> Option<Generation>

Returns the next generation number, or None if it would exceed Generation::MAX.

Source

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.

Source

pub const fn as_u64(self) -> u64

Returns the generation number as a u64.

Source

pub const fn as_i64(self) -> i64

Returns the generation number as an i64.

This conversion is infallible because generation numbers are restricted to 2**63 - 1.

Trait Implementations§

Source§

impl Arbitrary for Generation

Available on crate feature proptest1 only.

Generates random Generation instances.

Values are drawn uniformly from the range 0..=Generation::MAX.

Source§

type Parameters = GenerationParams

The type of parameters that arbitrary_with accepts for configuration of the generated Strategy. Parameters must implement Default.
Source§

type Strategy = BoxedStrategy<Generation>

The type of Strategy used to generate values of type Self.
Source§

fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy

Generates a Strategy for producing arbitrary values of type the implementing type (Self). The strategy is passed the arguments given in args. Read more
Source§

fn arbitrary() -> Self::Strategy

Generates a Strategy for producing arbitrary values of type the implementing type (Self). Read more
Source§

impl Clone for Generation

Source§

fn clone(&self) -> Generation

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Generation

Source§

impl Debug for Generation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Generation

Available on crate feature serde only.
Source§

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 Diffable for Generation

Available on crate feature daft01 only.

Diffs a Generation as a leaf value.

Generation numbers are scalars, so diffing stops at them.

Source§

type Diff<'daft> = Leaf<&'daft Generation>

The type of the diff. Read more
Source§

fn diff<'daft>(&'daft self, other: &'daft Self) -> Self::Diff<'daft>

Compute the diff between two values.
Source§

impl Display for Generation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Generation

Source§

impl From<&Generation> for i64

Source§

fn from(g: &Generation) -> Self

Converts to this type from the input type.
Source§

impl From<Generation> for u64

Source§

fn from(g: Generation) -> Self

Converts to this type from the input type.
Source§

impl From<Generation> for i64

Source§

fn from(g: Generation) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Generation

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Generation

Source§

type Err = ParseIntError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl GenericGeneration for Generation

Source§

fn from_untyped_generation(generation: Generation) -> Self

Creates a new instance of Self from an untyped Generation.
Source§

fn into_untyped_generation(self) -> Generation

Converts self into an untyped Generation.
Source§

fn as_untyped_generation(&self) -> &Generation

Returns the inner Generation. Read more
Source§

impl Hash for Generation

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl JsonSchema for Generation

Available on crate feature 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

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(_: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn is_referenceable() -> bool

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more
Source§

impl Ord for Generation

Source§

fn cmp(&self, other: &Generation) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Generation

Source§

fn eq(&self, other: &Generation) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Generation

Source§

fn partial_cmp(&self, other: &Generation) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Generation

Available on crate feature serde only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Generation

Source§

impl TryFrom<i64> for Generation

Source§

type Error = GenerationNegativeError

The type returned in the event of a conversion error.
Source§

fn try_from(value: i64) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u64> for Generation

Source§

type Error = GenerationOverflowError

The type returned in the event of a conversion error.
Source§

fn try_from(value: u64) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Value for Generation

Available on crate feature slog2 only.

Logs a Generation as an integer.

Source§

fn serialize( &self, _rec: &Record<'_>, key: Key, serializer: &mut dyn Serializer, ) -> Result

Serialize self into Serializer Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> SendSyncUnwindSafe for T
where T: Send + Sync + UnwindSafe + ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V