EntityGeneration

Struct EntityGeneration 

Source
pub struct EntityGeneration(/* private fields */);
Expand description

This tracks different versions or generations of an EntityRow. Importantly, this can wrap, meaning each generation is not necessarily unique per EntityRow.

This should be treated as a opaque identifier, and its internal representation may be subject to change.

§Aliasing

Internally EntityGeneration wraps a u32, so it can’t represent every possible generation. Eventually, generations can (and do) wrap or alias. This can cause Entity and EntityGeneration values to be equal while still referring to different conceptual entities. This can cause some surprising behavior:

let (aliased, did_alias) = EntityGeneration::FIRST.after_versions(1u32 << 31).after_versions_and_could_alias(1u32 << 31);
assert!(did_alias);
assert!(EntityGeneration::FIRST == aliased);

This can cause some unintended side effects. See Entity docs for practical concerns and how to minimize any risks.

Implementations§

Source§

impl EntityGeneration

Source

pub const FIRST: Self

Represents the first generation of an EntityRow.

Source

pub const fn to_bits(self) -> u32

Gets some bits that represent this value. The bits are opaque and should not be regarded as meaningful.

Source

pub const fn from_bits(bits: u32) -> Self

Reconstruct an EntityGeneration previously destructured with EntityGeneration::to_bits.

Only useful when applied to results from to_bits in the same instance of an application.

Source

pub const fn after_versions(self, versions: u32) -> Self

Returns the EntityGeneration that would result from this many more versions of the corresponding EntityRow from passing.

Source

pub const fn after_versions_and_could_alias(self, versions: u32) -> (Self, bool)

Identical to after_versions but also returns a bool indicating if, after these versions, one such version could conflict with a previous one.

If this happens, this will no longer uniquely identify a version of an EntityRow. This is called entity aliasing.

Source

pub const fn cmp_approx(&self, other: &Self) -> Ordering

Compares two generations.

Generations that are later will be Greater than earlier ones.

let later_generation = EntityGeneration::FIRST.after_versions(400);
assert_eq!(EntityGeneration::FIRST.cmp_approx(&later_generation), Ordering::Less);

let (aliased, did_alias) = EntityGeneration::FIRST.after_versions(400).after_versions_and_could_alias(u32::MAX);
assert!(did_alias);
assert_eq!(EntityGeneration::FIRST.cmp_approx(&aliased), Ordering::Less);

Ordering will be incorrect and non-transitive for distant generations:

let later_generation = EntityGeneration::FIRST.after_versions(3u32 << 31);
let much_later_generation = later_generation.after_versions(3u32 << 31);

// while these orderings are correct and pass assertions...
assert_eq!(EntityGeneration::FIRST.cmp_approx(&later_generation), Ordering::Less);
assert_eq!(later_generation.cmp_approx(&much_later_generation), Ordering::Less);

// ... this ordering is not and the assertion fails!
assert_eq!(EntityGeneration::FIRST.cmp_approx(&much_later_generation), Ordering::Less);

Because of this, EntityGeneration does not implement Ord/PartialOrd.

Trait Implementations§

Source§

impl Clone for EntityGeneration

Source§

fn clone(&self) -> EntityGeneration

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for EntityGeneration

Source§

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

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

impl Display for EntityGeneration

Source§

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

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

impl Hash for EntityGeneration

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 PartialEq for EntityGeneration

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for EntityGeneration

Source§

impl Eq for EntityGeneration

Source§

impl StructuralPartialEq for EntityGeneration

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<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> DynEq for T
where T: Any + Eq,

Source§

fn dyn_eq(&self, other: &(dyn DynEq + 'static)) -> bool

This method tests for self and other values to be equal. Read more
Source§

impl<T> DynHash for T
where T: DynEq + Hash,

Source§

fn dyn_hash(&self, state: &mut dyn Hasher)

Feeds this value into the given Hasher.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
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<T> ConditionalSend for T
where T: Send,