use crate::all_storages::AllStorages;
use crate::atomic_refcell::{ExclusiveBorrow, Ref, RefMut, SharedBorrow};
use crate::component::{Component, Unique};
use crate::entities::Entities;
use crate::entity_id::EntityId;
use crate::error;
use crate::get::Get;
use crate::sparse_set::SparseSet;
use crate::storage::StorageId;
use crate::track::{self, Tracking};
use crate::tracking::{Inserted, InsertedOrModified, Modified};
use crate::unique::UniqueStorage;
use core::fmt;
use core::ops::{Deref, DerefMut};
pub struct AllStoragesView<'a>(pub(crate) Ref<'a, &'a AllStorages>);
impl Clone for AllStoragesView<'_> {
#[inline]
fn clone(&self) -> Self {
AllStoragesView(self.0.clone())
}
}
impl Deref for AllStoragesView<'_> {
type Target = AllStorages;
#[inline]
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl AsRef<AllStorages> for AllStoragesView<'_> {
#[inline]
fn as_ref(&self) -> &AllStorages {
&self.0
}
}
pub struct AllStoragesViewMut<'a>(pub(crate) RefMut<'a, &'a mut AllStorages>);
impl Deref for AllStoragesViewMut<'_> {
type Target = AllStorages;
#[inline]
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for AllStoragesViewMut<'_> {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl AsRef<AllStorages> for AllStoragesViewMut<'_> {
#[inline]
fn as_ref(&self) -> &AllStorages {
&self.0
}
}
impl AsMut<AllStorages> for AllStoragesViewMut<'_> {
#[inline]
fn as_mut(&mut self) -> &mut AllStorages {
&mut self.0
}
}
pub struct EntitiesView<'a> {
pub(crate) entities: &'a Entities,
pub(crate) borrow: Option<SharedBorrow<'a>>,
pub(crate) all_borrow: Option<SharedBorrow<'a>>,
}
impl Deref for EntitiesView<'_> {
type Target = Entities;
#[inline]
fn deref(&self) -> &Self::Target {
self.entities
}
}
impl Clone for EntitiesView<'_> {
#[inline]
fn clone(&self) -> Self {
EntitiesView {
entities: self.entities,
borrow: self.borrow.clone(),
all_borrow: self.all_borrow.clone(),
}
}
}
pub struct EntitiesViewMut<'a> {
pub(crate) entities: &'a mut Entities,
pub(crate) _borrow: Option<ExclusiveBorrow<'a>>,
pub(crate) _all_borrow: Option<SharedBorrow<'a>>,
}
impl Deref for EntitiesViewMut<'_> {
type Target = Entities;
#[inline]
fn deref(&self) -> &Self::Target {
self.entities
}
}
impl DerefMut for EntitiesViewMut<'_> {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
self.entities
}
}
pub struct View<'a, T: Component, Tracking: track::Tracking = <T as Component>::Tracking> {
pub(crate) sparse_set: &'a SparseSet<T, Tracking>,
pub(crate) all_borrow: Option<SharedBorrow<'a>>,
pub(crate) borrow: Option<SharedBorrow<'a>>,
pub(crate) last_insert: u32,
pub(crate) last_modification: u32,
pub(crate) last_removal_or_deletion: u32,
pub(crate) current: u32,
}
impl<'a, T: Component> View<'a, T> {
#[inline]
pub fn is_inserted(&self, entity: EntityId) -> bool {
T::Tracking::is_inserted(self.sparse_set, entity, self.last_insert, self.current)
}
#[inline]
pub fn is_modified(&self, entity: EntityId) -> bool {
T::Tracking::is_modified(
self.sparse_set,
entity,
self.last_modification,
self.current,
)
}
#[inline]
pub fn is_inserted_or_modified(&self, entity: EntityId) -> bool {
self.is_inserted(entity) || self.is_modified(entity)
}
#[inline]
pub fn is_deleted(&self, entity: EntityId) -> bool {
T::Tracking::is_deleted(self, entity, self.last_removal_or_deletion, self.current)
}
#[inline]
pub fn is_removed(&self, entity: EntityId) -> bool {
T::Tracking::is_removed(self, entity, self.last_removal_or_deletion, self.current)
}
#[inline]
pub fn is_removed_or_deleted(&self, entity: EntityId) -> bool {
self.is_removed(entity) || self.is_deleted(entity)
}
}
impl<'a, T: Component<Tracking = track::Untracked>> View<'a, T, track::Untracked> {
pub fn new_for_custom_storage(
storage_id: StorageId,
all_storages: Ref<'a, &'a AllStorages>,
) -> Result<Self, error::CustomStorageView> {
use crate::all_storages::CustomStorageAccess;
let (all_storages, all_borrow) = unsafe { Ref::destructure(all_storages) };
let storage = all_storages.custom_storage_by_id(storage_id)?;
let (storage, borrow) = unsafe { Ref::destructure(storage) };
if let Some(sparse_set) = storage.as_any().downcast_ref() {
Ok(View {
sparse_set,
all_borrow: Some(all_borrow),
borrow: Some(borrow),
last_insert: 0,
last_modification: 0,
last_removal_or_deletion: 0,
current: 0,
})
} else {
Err(error::CustomStorageView::WrongType(storage.name()))
}
}
}
impl<T: Component<Tracking = track::Insertion>> View<'_, T, track::Insertion> {
#[inline]
pub fn inserted(&self) -> Inserted<&Self> {
Inserted(self)
}
#[inline]
pub fn inserted_or_modified(&self) -> InsertedOrModified<&Self> {
InsertedOrModified(self)
}
}
impl<T: Component<Tracking = track::Modification>> View<'_, T, track::Modification> {
#[inline]
pub fn modified(&self) -> Modified<&Self> {
Modified(self)
}
#[inline]
pub fn inserted_or_modified(&self) -> InsertedOrModified<&Self> {
InsertedOrModified(self)
}
}
impl<T: Component<Tracking = track::Deletion>> View<'_, T, track::Deletion> {
pub fn deleted(&self) -> impl Iterator<Item = (EntityId, &T)> + '_ {
self.sparse_set
.deletion_data
.iter()
.filter_map(move |(entity, timestamp, component)| {
if track::is_track_within_bounds(
*timestamp,
self.last_removal_or_deletion,
self.current,
) {
Some((*entity, component))
} else {
None
}
})
}
pub fn removed_or_deleted(&self) -> impl Iterator<Item = EntityId> + '_ {
self.sparse_set
.deletion_data
.iter()
.filter_map(move |(entity, timestamp, _)| {
if track::is_track_within_bounds(
*timestamp,
self.last_removal_or_deletion,
self.current,
) {
Some(*entity)
} else {
None
}
})
}
}
impl<T: Component<Tracking = track::Removal>> View<'_, T, track::Removal> {
pub fn removed(&self) -> impl Iterator<Item = EntityId> + '_ {
self.sparse_set
.removal_data
.iter()
.filter_map(move |(entity, timestamp)| {
if track::is_track_within_bounds(
*timestamp,
self.last_removal_or_deletion,
self.current,
) {
Some(*entity)
} else {
None
}
})
}
pub fn removed_or_deleted(&self) -> impl Iterator<Item = EntityId> + '_ {
self.sparse_set
.removal_data
.iter()
.filter_map(move |(entity, timestamp)| {
if track::is_track_within_bounds(
*timestamp,
self.last_removal_or_deletion,
self.current,
) {
Some(*entity)
} else {
None
}
})
}
}
impl<T: Component<Tracking = track::All>> View<'_, T, track::All> {
#[inline]
pub fn inserted(&self) -> Inserted<&Self> {
Inserted(self)
}
#[inline]
pub fn modified(&self) -> Modified<&Self> {
Modified(self)
}
#[inline]
pub fn inserted_or_modified(&self) -> InsertedOrModified<&Self> {
InsertedOrModified(self)
}
pub fn deleted(&self) -> impl Iterator<Item = (EntityId, &T)> + '_ {
self.sparse_set
.deletion_data
.iter()
.filter_map(move |(entity, timestamp, component)| {
if track::is_track_within_bounds(
*timestamp,
self.last_removal_or_deletion,
self.current,
) {
Some((*entity, component))
} else {
None
}
})
}
pub fn removed(&self) -> impl Iterator<Item = EntityId> + '_ {
self.sparse_set
.removal_data
.iter()
.filter_map(move |(entity, timestamp)| {
if track::is_track_within_bounds(
*timestamp,
self.last_removal_or_deletion,
self.current,
) {
Some(*entity)
} else {
None
}
})
}
pub fn removed_or_deleted(&self) -> impl Iterator<Item = EntityId> + '_ {
self.sparse_set
.deletion_data
.iter()
.filter_map(move |(entity, timestamp, _)| {
if track::is_track_within_bounds(
*timestamp,
self.last_removal_or_deletion,
self.current,
) {
Some(*entity)
} else {
None
}
})
.chain(
self.sparse_set
.removal_data
.iter()
.filter_map(move |(entity, timestamp)| {
if track::is_track_within_bounds(*timestamp, self.last_insert, self.current)
{
Some(*entity)
} else {
None
}
}),
)
}
}
impl<'a, T: Component> Deref for View<'a, T> {
type Target = SparseSet<T>;
#[inline]
fn deref(&self) -> &Self::Target {
self.sparse_set
}
}
impl<'a, T: Component> AsRef<SparseSet<T>> for View<'a, T> {
#[inline]
fn as_ref(&self) -> &SparseSet<T> {
self.sparse_set
}
}
impl<'a, T: Component> Clone for View<'a, T> {
#[inline]
fn clone(&self) -> Self {
View {
sparse_set: self.sparse_set,
borrow: self.borrow.clone(),
all_borrow: self.all_borrow.clone(),
last_insert: self.last_insert,
last_modification: self.last_modification,
last_removal_or_deletion: self.last_removal_or_deletion,
current: self.current,
}
}
}
impl<T: fmt::Debug + Component> fmt::Debug for View<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.sparse_set.fmt(f)
}
}
impl<T: Component> core::ops::Index<EntityId> for View<'_, T> {
type Output = T;
#[track_caller]
#[inline]
fn index(&self, entity: EntityId) -> &Self::Output {
self.get(entity).unwrap()
}
}
pub struct ViewMut<'a, T: Component, Tracking: track::Tracking = <T as Component>::Tracking> {
pub(crate) sparse_set: &'a mut SparseSet<T, Tracking>,
pub(crate) _all_borrow: Option<SharedBorrow<'a>>,
pub(crate) _borrow: Option<ExclusiveBorrow<'a>>,
pub(crate) last_insert: u32,
pub(crate) last_modification: u32,
pub(crate) last_removal_or_deletion: u32,
pub(crate) current: u32,
}
impl<'a, T: Component<Tracking = track::Untracked>> ViewMut<'a, T, track::Untracked> {
pub fn new_for_custom_storage(
storage_id: StorageId,
all_storages: Ref<'a, &'a AllStorages>,
) -> Result<Self, error::CustomStorageView> {
use crate::all_storages::CustomStorageAccess;
let (all_storages, all_borrow) = unsafe { Ref::destructure(all_storages) };
let storage = all_storages.custom_storage_mut_by_id(storage_id)?;
let (storage, borrow) = unsafe { RefMut::destructure(storage) };
let name = storage.name();
if let Some(sparse_set) = storage.any_mut().downcast_mut() {
Ok(ViewMut {
sparse_set,
_all_borrow: Some(all_borrow),
_borrow: Some(borrow),
last_insert: 0,
last_modification: 0,
last_removal_or_deletion: 0,
current: 0,
})
} else {
Err(error::CustomStorageView::WrongType(name))
}
}
}
impl<'a, T: Component> ViewMut<'a, T> {
#[track_caller]
#[inline]
pub fn apply<R, F: FnOnce(&mut T, &T) -> R>(&mut self, a: EntityId, b: EntityId, f: F) -> R {
T::Tracking::apply(self, a, b, f)
}
#[track_caller]
#[inline]
pub fn apply_mut<R, F: FnOnce(&mut T, &mut T) -> R>(
&mut self,
a: EntityId,
b: EntityId,
f: F,
) -> R {
T::Tracking::apply_mut(self, a, b, f)
}
#[inline]
pub fn is_inserted(&self, entity: EntityId) -> bool {
T::Tracking::is_inserted(self.sparse_set, entity, self.last_insert, self.current)
}
#[inline]
pub fn is_modified(&self, entity: EntityId) -> bool {
T::Tracking::is_modified(
self.sparse_set,
entity,
self.last_modification,
self.current,
)
}
#[inline]
pub fn is_inserted_or_modified(&self, entity: EntityId) -> bool {
self.is_inserted(entity) || self.is_modified(entity)
}
#[inline]
pub fn is_deleted(&self, entity: EntityId) -> bool {
T::Tracking::is_deleted(self, entity, self.last_removal_or_deletion, self.current)
}
#[inline]
pub fn is_removed(&self, entity: EntityId) -> bool {
T::Tracking::is_removed(self, entity, self.last_removal_or_deletion, self.current)
}
#[inline]
pub fn is_removed_or_deleted(&self, entity: EntityId) -> bool {
self.is_removed(entity) || self.is_deleted(entity)
}
pub fn clear(&mut self) {
self.sparse_set.private_clear(self.current);
}
}
impl<T: Component<Tracking = track::Insertion>> ViewMut<'_, T, track::Insertion> {
#[inline]
pub fn inserted(&self) -> Inserted<&Self> {
Inserted(self)
}
#[inline]
pub fn inserted_or_modified(&self) -> InsertedOrModified<&Self> {
InsertedOrModified(self)
}
#[inline]
pub fn inserted_mut(&mut self) -> Inserted<&mut Self> {
Inserted(self)
}
#[inline]
pub fn inserted_or_modified_mut(&mut self) -> InsertedOrModified<&mut Self> {
InsertedOrModified(self)
}
#[inline]
pub fn clear_all_inserted(self) {
self.sparse_set.private_clear_all_inserted(self.current);
}
}
impl<T: Component<Tracking = track::Modification>> ViewMut<'_, T, track::Modification> {
#[inline]
pub fn modified(&self) -> Modified<&Self> {
Modified(self)
}
#[inline]
pub fn inserted_or_modified(&self) -> InsertedOrModified<&Self> {
InsertedOrModified(self)
}
#[inline]
pub fn modified_mut(&mut self) -> Modified<&mut Self> {
Modified(self)
}
#[inline]
pub fn inserted_or_modified_mut(&mut self) -> InsertedOrModified<&mut Self> {
InsertedOrModified(self)
}
#[inline]
pub fn clear_all_modified(self) {
self.sparse_set.private_clear_all_modified(self.current);
}
}
impl<T: Component<Tracking = track::Deletion>> ViewMut<'_, T, track::Deletion> {
pub fn deleted(&self) -> impl Iterator<Item = (EntityId, &T)> + '_ {
self.sparse_set
.deletion_data
.iter()
.filter_map(move |(entity, timestamp, component)| {
if track::is_track_within_bounds(
*timestamp,
self.last_removal_or_deletion,
self.current,
) {
Some((*entity, component))
} else {
None
}
})
}
pub fn removed_or_deleted(&self) -> impl Iterator<Item = EntityId> + '_ {
self.sparse_set
.deletion_data
.iter()
.filter_map(move |(entity, timestamp, _)| {
if track::is_track_within_bounds(
*timestamp,
self.last_removal_or_deletion,
self.current,
) {
Some(*entity)
} else {
None
}
})
}
}
impl<T: Component<Tracking = track::Removal>> ViewMut<'_, T, track::Removal> {
pub fn removed(&self) -> impl Iterator<Item = EntityId> + '_ {
self.sparse_set
.removal_data
.iter()
.filter_map(move |(entity, timestamp)| {
if track::is_track_within_bounds(
*timestamp,
self.last_removal_or_deletion,
self.current,
) {
Some(*entity)
} else {
None
}
})
}
pub fn removed_or_deleted(&self) -> impl Iterator<Item = EntityId> + '_ {
self.sparse_set
.removal_data
.iter()
.filter_map(move |(entity, timestamp)| {
if track::is_track_within_bounds(
*timestamp,
self.last_removal_or_deletion,
self.current,
) {
Some(*entity)
} else {
None
}
})
}
}
impl<T: Component<Tracking = track::All>> ViewMut<'_, T, track::All> {
#[inline]
pub fn inserted(&self) -> Inserted<&Self> {
Inserted(self)
}
#[inline]
pub fn modified(&self) -> Modified<&Self> {
Modified(self)
}
#[inline]
pub fn inserted_or_modified(&self) -> InsertedOrModified<&Self> {
InsertedOrModified(self)
}
#[inline]
pub fn inserted_mut(&mut self) -> Inserted<&mut Self> {
Inserted(self)
}
#[inline]
pub fn modified_mut(&mut self) -> Modified<&mut Self> {
Modified(self)
}
#[inline]
pub fn inserted_or_modified_mut(&mut self) -> InsertedOrModified<&mut Self> {
InsertedOrModified(self)
}
#[inline]
pub fn clear_all_inserted(self) {
self.sparse_set.private_clear_all_inserted(self.current);
}
#[inline]
pub fn clear_all_modified(self) {
self.sparse_set.private_clear_all_modified(self.current);
}
#[inline]
pub fn clear_all_inserted_and_modified(self) {
self.sparse_set
.private_clear_all_inserted_and_modified(self.current);
}
pub fn deleted(&self) -> impl Iterator<Item = (EntityId, &T)> + '_ {
self.sparse_set
.deletion_data
.iter()
.filter_map(move |(entity, timestamp, component)| {
if track::is_track_within_bounds(
*timestamp,
self.last_removal_or_deletion,
self.current,
) {
Some((*entity, component))
} else {
None
}
})
}
pub fn removed(&self) -> impl Iterator<Item = EntityId> + '_ {
self.sparse_set
.removal_data
.iter()
.filter_map(move |(entity, timestamp)| {
if track::is_track_within_bounds(
*timestamp,
self.last_removal_or_deletion,
self.current,
) {
Some(*entity)
} else {
None
}
})
}
pub fn removed_or_deleted(&self) -> impl Iterator<Item = EntityId> + '_ {
self.sparse_set
.deletion_data
.iter()
.filter_map(move |(entity, timestamp, _)| {
if track::is_track_within_bounds(
*timestamp,
self.last_removal_or_deletion,
self.current,
) {
Some(*entity)
} else {
None
}
})
.chain(
self.sparse_set
.removal_data
.iter()
.filter_map(move |(entity, timestamp)| {
if track::is_track_within_bounds(*timestamp, self.last_insert, self.current)
{
Some(*entity)
} else {
None
}
}),
)
}
}
impl<T: Component> Deref for ViewMut<'_, T> {
type Target = SparseSet<T>;
#[inline]
fn deref(&self) -> &Self::Target {
self.sparse_set
}
}
impl<T: Component> DerefMut for ViewMut<'_, T> {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
self.sparse_set
}
}
impl<'a, T: Component> AsRef<SparseSet<T>> for ViewMut<'a, T> {
#[inline]
fn as_ref(&self) -> &SparseSet<T> {
self.sparse_set
}
}
impl<'a, T: Component> AsMut<SparseSet<T>> for ViewMut<'a, T> {
#[inline]
fn as_mut(&mut self) -> &mut SparseSet<T> {
self.sparse_set
}
}
impl<'a, T: Component> AsMut<Self> for ViewMut<'a, T> {
#[inline]
fn as_mut(&mut self) -> &mut Self {
self
}
}
impl<T: fmt::Debug + Component> fmt::Debug for ViewMut<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.sparse_set.fmt(f)
}
}
impl<'a, T: Component> core::ops::Index<EntityId> for ViewMut<'a, T> {
type Output = T;
#[inline]
fn index(&self, entity: EntityId) -> &Self::Output {
self.get(entity).unwrap()
}
}
impl<'a, T: Component<Tracking = track::Untracked>> core::ops::IndexMut<EntityId>
for ViewMut<'a, T, track::Untracked>
{
#[inline]
fn index_mut(&mut self, entity: EntityId) -> &mut Self::Output {
(&mut *self).get(entity).unwrap()
}
}
impl<'a, T: Component<Tracking = track::Insertion>> core::ops::IndexMut<EntityId>
for ViewMut<'a, T, track::Insertion>
{
#[inline]
fn index_mut(&mut self, entity: EntityId) -> &mut Self::Output {
(&mut *self).get(entity).unwrap()
}
}
impl<'a, T: Component<Tracking = track::Deletion>> core::ops::IndexMut<EntityId>
for ViewMut<'a, T, track::Deletion>
{
#[inline]
fn index_mut(&mut self, entity: EntityId) -> &mut Self::Output {
(&mut *self).get(entity).unwrap()
}
}
impl<'a, T: Component<Tracking = track::Removal>> core::ops::IndexMut<EntityId>
for ViewMut<'a, T, track::Removal>
{
#[inline]
fn index_mut(&mut self, entity: EntityId) -> &mut Self::Output {
(&mut *self).get(entity).unwrap()
}
}
impl<'a, T: Component<Tracking = track::Modification>> core::ops::IndexMut<EntityId>
for ViewMut<'a, T, track::Modification>
{
#[inline]
fn index_mut(&mut self, entity: EntityId) -> &mut Self::Output {
let index = self
.index_of(entity)
.ok_or_else(|| error::MissingComponent {
id: entity,
name: core::any::type_name::<T>(),
})
.unwrap();
let SparseSet {
data,
modification_data,
..
} = self.sparse_set;
unsafe {
*modification_data.get_unchecked_mut(index) = self.current;
};
unsafe { data.get_unchecked_mut(index) }
}
}
impl<'a, T: Component<Tracking = track::All>> core::ops::IndexMut<EntityId>
for ViewMut<'a, T, track::All>
{
#[inline]
fn index_mut(&mut self, entity: EntityId) -> &mut Self::Output {
let index = self
.index_of(entity)
.ok_or_else(|| error::MissingComponent {
id: entity,
name: core::any::type_name::<T>(),
})
.unwrap();
let SparseSet {
data,
modification_data,
..
} = self.sparse_set;
unsafe {
*modification_data.get_unchecked_mut(index) = self.current;
};
unsafe { data.get_unchecked_mut(index) }
}
}
pub struct UniqueView<'a, T: Unique> {
pub(crate) unique: &'a UniqueStorage<T>,
pub(crate) borrow: Option<SharedBorrow<'a>>,
pub(crate) all_borrow: Option<SharedBorrow<'a>>,
pub(crate) last_insert: u32,
pub(crate) last_modification: u32,
pub(crate) current: u32,
}
impl<T: Unique> UniqueView<'_, T> {
#[allow(clippy::should_implement_trait)]
#[inline]
pub fn clone(unique: &Self) -> Self {
UniqueView {
unique: unique.unique,
borrow: unique.borrow.clone(),
all_borrow: unique.all_borrow.clone(),
last_insert: unique.last_insert,
last_modification: unique.last_modification,
current: unique.current,
}
}
}
impl<T: Unique> UniqueView<'_, T> {
#[inline]
pub fn is_inserted(&self) -> bool {
crate::track::is_track_within_bounds(self.unique.insert, self.last_insert, self.current)
}
#[inline]
pub fn is_modified(&self) -> bool {
crate::track::is_track_within_bounds(
self.unique.modification,
self.last_modification,
self.current,
)
}
#[inline]
pub fn is_inserted_or_modified(&self) -> bool {
self.is_inserted() || self.is_modified()
}
}
impl<T: Unique> Deref for UniqueView<'_, T> {
type Target = T;
#[inline]
fn deref(&self) -> &Self::Target {
&self.unique.value
}
}
impl<T: Unique> AsRef<T> for UniqueView<'_, T> {
#[inline]
fn as_ref(&self) -> &T {
&self.unique.value
}
}
impl<T: fmt::Debug + Unique> fmt::Debug for UniqueView<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.unique.value.fmt(f)
}
}
pub struct UniqueViewMut<'a, T: Unique> {
pub(crate) unique: &'a mut UniqueStorage<T>,
pub(crate) _borrow: Option<ExclusiveBorrow<'a>>,
pub(crate) _all_borrow: Option<SharedBorrow<'a>>,
pub(crate) last_insert: u32,
pub(crate) last_modification: u32,
pub(crate) current: u32,
}
impl<T: Unique> UniqueViewMut<'_, T> {
#[inline]
pub fn is_inserted(&self) -> bool {
crate::track::is_track_within_bounds(self.unique.insert, self.last_insert, self.current)
}
#[inline]
pub fn is_modified(&self) -> bool {
crate::track::is_track_within_bounds(
self.unique.modification,
self.last_modification,
self.current,
)
}
#[inline]
pub fn is_inserted_or_modified(&self) -> bool {
self.is_inserted() || self.is_modified()
}
#[inline]
pub fn clear_inserted(self) {
self.unique.last_insert = self.current;
}
#[inline]
pub fn clear_modified(self) {
self.unique.last_modification = self.current;
}
#[inline]
pub fn clear_inserted_and_modified(self) {
self.unique.last_insert = self.current;
self.unique.last_modification = self.current;
}
}
impl<T: Unique> Deref for UniqueViewMut<'_, T> {
type Target = T;
#[inline]
fn deref(&self) -> &Self::Target {
&self.unique.value
}
}
impl<T: Unique> DerefMut for UniqueViewMut<'_, T> {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
self.unique.modification = self.current;
&mut self.unique.value
}
}
impl<T: Unique> AsRef<T> for UniqueViewMut<'_, T> {
#[inline]
fn as_ref(&self) -> &T {
&self.unique.value
}
}
impl<T: Unique> AsMut<T> for UniqueViewMut<'_, T> {
#[inline]
fn as_mut(&mut self) -> &mut T {
self.unique.modification = self.current;
&mut self.unique.value
}
}
impl<T: fmt::Debug + Unique> fmt::Debug for UniqueViewMut<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.unique.value.fmt(f)
}
}