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
impl EntityGeneration
Sourcepub const fn to_bits(self) -> u32
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.
Sourcepub const fn from_bits(bits: u32) -> Self
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.
Sourcepub const fn after_versions(self, versions: u32) -> Self
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.
Sourcepub const fn after_versions_and_could_alias(self, versions: u32) -> (Self, bool)
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.
Sourcepub const fn cmp_approx(&self, other: &Self) -> Ordering
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
impl Clone for EntityGeneration
Source§fn clone(&self) -> EntityGeneration
fn clone(&self) -> EntityGeneration
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EntityGeneration
impl Debug for EntityGeneration
Source§impl Display for EntityGeneration
impl Display for EntityGeneration
Source§impl Hash for EntityGeneration
impl Hash for EntityGeneration
Source§impl PartialEq for EntityGeneration
impl PartialEq for EntityGeneration
impl Copy for EntityGeneration
impl Eq for EntityGeneration
impl StructuralPartialEq for EntityGeneration
Auto Trait Implementations§
impl Freeze for EntityGeneration
impl RefUnwindSafe for EntityGeneration
impl Send for EntityGeneration
impl Sync for EntityGeneration
impl Unpin for EntityGeneration
impl UnwindSafe for EntityGeneration
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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
key and return true if they are equal.