diff --git a/all-is-cubes/src/behavior.rs b/all-is-cubes/src/behavior.rs index 20f558230..83556776a 100644 --- a/all-is-cubes/src/behavior.rs +++ b/all-is-cubes/src/behavior.rs @@ -563,7 +563,7 @@ impl BehaviorSetTransaction { } impl Transaction> for BehaviorSetTransaction { - type CommitCheck = CommitCheck; + type CommitCheck = impl fmt::Debug; type Output = transaction::NoOutput; #[allow(clippy::vtable_address_comparisons)] // The hazards should be okay for this use case @@ -667,7 +667,7 @@ impl Transaction> for BehaviorSetTransaction } impl transaction::Merge for BehaviorSetTransaction { - type MergeCheck = MergeCheck; + type MergeCheck = impl fmt::Debug; type Conflict = BehaviorTransactionConflict; fn check_merge(&self, other: &Self) -> Result { diff --git a/all-is-cubes/src/block/block_def.rs b/all-is-cubes/src/block/block_def.rs index 8aa2529d5..368e64ef0 100644 --- a/all-is-cubes/src/block/block_def.rs +++ b/all-is-cubes/src/block/block_def.rs @@ -302,7 +302,7 @@ impl BlockDefTransaction { } impl Transaction for BlockDefTransaction { - type CommitCheck = (); + type CommitCheck = impl fmt::Debug; type Output = transaction::NoOutput; fn check( @@ -335,7 +335,7 @@ impl Transaction for BlockDefTransaction { } impl transaction::Merge for BlockDefTransaction { - type MergeCheck = (); + type MergeCheck = impl fmt::Debug; type Conflict = BlockDefConflict; fn check_merge(&self, other: &Self) -> Result { diff --git a/all-is-cubes/src/character.rs b/all-is-cubes/src/character.rs index ff202b75e..584f7a9d9 100644 --- a/all-is-cubes/src/character.rs +++ b/all-is-cubes/src/character.rs @@ -757,11 +757,7 @@ impl CharacterTransaction { #[allow(clippy::type_complexity)] impl Transaction for CharacterTransaction { - type CommitCheck = ( - >::CommitCheck, - >::CommitCheck, - as Transaction>>::CommitCheck, - ); + type CommitCheck = impl fmt::Debug; type Output = transaction::NoOutput; fn check(&self, target: &Character) -> Result { @@ -807,11 +803,7 @@ impl Transaction for CharacterTransaction { } impl Merge for CharacterTransaction { - type MergeCheck = ( - ::MergeCheck, - ::MergeCheck, - as Merge>::MergeCheck, - ); + type MergeCheck = impl fmt::Debug; type Conflict = CharacterTransactionConflict; fn check_merge(&self, other: &Self) -> Result { diff --git a/all-is-cubes/src/inv/inventory.rs b/all-is-cubes/src/inv/inventory.rs index b9c95a908..764429c94 100644 --- a/all-is-cubes/src/inv/inventory.rs +++ b/all-is-cubes/src/inv/inventory.rs @@ -5,6 +5,7 @@ use alloc::collections::BTreeMap; use alloc::sync::Arc; use alloc::vec::Vec; use core::num::NonZeroU16; +use core::fmt; use crate::block::Block; use crate::character::{Character, CharacterTransaction, Cursor}; @@ -342,13 +343,13 @@ impl InventoryTransaction { } impl Transaction for InventoryTransaction { - type CommitCheck = Option; + type CommitCheck = impl fmt::Debug; type Output = InventoryChange; fn check(&self, inventory: &Inventory) -> Result { // Don't do the expensive copy if we have one already if self.replace.is_empty() && self.insert.is_empty() { - return Ok(None); + return Ok(None::); } // The simplest bulletproof algorithm to ensure we're stacking everything right @@ -425,7 +426,7 @@ impl Transaction for InventoryTransaction { } impl Merge for InventoryTransaction { - type MergeCheck = (); + type MergeCheck = impl fmt::Debug; type Conflict = InventoryConflict; fn check_merge(&self, other: &Self) -> Result { diff --git a/all-is-cubes/src/lib.rs b/all-is-cubes/src/lib.rs index eacfc64ea..b71a89cf8 100644 --- a/all-is-cubes/src/lib.rs +++ b/all-is-cubes/src/lib.rs @@ -1,3 +1,4 @@ +#![feature(impl_trait_in_assoc_type)] #![feature(never_type)] //! All is Cubes is a game/engine for worlds made of cubical blocks, where the blocks diff --git a/all-is-cubes/src/physics/body.rs b/all-is-cubes/src/physics/body.rs index 9bb6267d7..1f44fdcf8 100644 --- a/all-is-cubes/src/physics/body.rs +++ b/all-is-cubes/src/physics/body.rs @@ -696,7 +696,7 @@ impl transaction::Transactional for Body { } impl Transaction for BodyTransaction { - type CommitCheck = (); + type CommitCheck = impl fmt::Debug; type Output = transaction::NoOutput; fn check(&self, _body: &Body) -> Result { @@ -716,7 +716,7 @@ impl Transaction for BodyTransaction { } impl transaction::Merge for BodyTransaction { - type MergeCheck = (); + type MergeCheck = impl fmt::Debug; type Conflict = core::convert::Infallible; fn check_merge(&self, _other: &Self) -> Result { diff --git a/all-is-cubes/src/space/space_txn.rs b/all-is-cubes/src/space/space_txn.rs index c031654cf..eb241b956 100644 --- a/all-is-cubes/src/space/space_txn.rs +++ b/all-is-cubes/src/space/space_txn.rs @@ -7,7 +7,7 @@ use alloc::sync::Arc; use alloc::vec::Vec; use core::{fmt, mem}; -use crate::behavior::{self, BehaviorSet, BehaviorSetTransaction}; +use crate::behavior::{self, BehaviorSetTransaction}; use crate::block::Block; use crate::drawing::DrawingPlane; use crate::fluff::Fluff; @@ -169,8 +169,7 @@ impl SpaceTransaction { } impl Transaction for SpaceTransaction { - type CommitCheck = - as Transaction>>::CommitCheck; + type CommitCheck = impl fmt::Debug; type Output = NoOutput; fn check(&self, space: &Space) -> Result { @@ -284,7 +283,7 @@ impl Transaction for SpaceTransaction { } impl Merge for SpaceTransaction { - type MergeCheck = as Merge>::MergeCheck; + type MergeCheck = impl fmt::Debug; type Conflict = SpaceTransactionConflict; fn check_merge(&self, other: &Self) -> Result { @@ -498,6 +497,7 @@ impl CubeTransaction { } impl Merge for CubeTransaction { + /// Not opaque because [`SpaceTransaction`] uses it type MergeCheck = CubeMergeCheck; type Conflict = CubeConflict; diff --git a/all-is-cubes/src/transaction.rs b/all-is-cubes/src/transaction.rs index 8e803dbf1..66206d794 100644 --- a/all-is-cubes/src/transaction.rs +++ b/all-is-cubes/src/transaction.rs @@ -39,7 +39,7 @@ pub trait Transaction: Merge { /// This may be used to pass precalculated values to speed up the commit phase, /// or even lock guards or similar, but also makes it slightly harder to accidentally /// call `commit` without `check`. - type CommitCheck: 'static; + type CommitCheck: fmt::Debug + 'static; /// The results of a [`Transaction::commit()`] or [`Transaction::execute()`]. /// Each commit may produce any number of these messages. @@ -127,7 +127,7 @@ pub trait Merge: Sized { /// Type of a value passed from [`Merge::check_merge`] to [`Merge::commit_merge`]. /// This may be used to pass precalculated values to speed up the merge phase, /// but also makes it difficult to accidentally merge without checking. - type MergeCheck: 'static; + type MergeCheck: fmt::Debug + 'static; /// Error type giving the reason why a merge was not possible. /// diff --git a/all-is-cubes/src/universe/members.rs b/all-is-cubes/src/universe/members.rs index e90a41669..6f47b4c30 100644 --- a/all-is-cubes/src/universe/members.rs +++ b/all-is-cubes/src/universe/members.rs @@ -308,7 +308,7 @@ macro_rules! member_enums_and_impls { ) -> Result { Ok(match self { Self::Noop => Box::new(()), - $( Self::$member_type(t) => Box::new(t.check(&())?), )* + $( Self::$member_type(t) => Box::new(t.check(&())?) as ut::AnyTransactionCheck, )* }) } diff --git a/all-is-cubes/src/universe/universe_txn.rs b/all-is-cubes/src/universe/universe_txn.rs index ffcc4ad8d..d0e93568d 100644 --- a/all-is-cubes/src/universe/universe_txn.rs +++ b/all-is-cubes/src/universe/universe_txn.rs @@ -82,6 +82,15 @@ where check: >::CommitCheck, } +impl fmt::Debug for TransactionInUniverseCheck +where + O: Transactional + 'static, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.check.fmt(f) + } +} + impl Merge for TransactionInUniverse where O: Transactional + 'static, @@ -204,18 +213,20 @@ pub struct UniverseTransaction { } // TODO: Benchmark cheaper HashMaps / using BTreeMap here -#[doc(hidden)] // Almost certainly will never need to be used explicitly #[derive(Debug)] +#[doc(hidden)] // Almost certainly will never need to be used explicitly pub struct UniverseMergeCheck { members: HbHashMap, - behaviors: behavior::MergeCheck, + behaviors: as Merge>::MergeCheck, } #[doc(hidden)] // Almost certainly will never need to be used explicitly #[derive(Debug)] -pub struct UniverseCommitCheck { +struct UniverseCommitCheck { members: HbHashMap, anonymous_insertions: Vec, - behaviors: behavior::CommitCheck, + behaviors: as Transaction< + behavior::BehaviorSet, + >>::CommitCheck, } /// Transaction conflict error type for [`UniverseTransaction`]. @@ -345,7 +356,7 @@ impl From for UniverseTransaction { } impl Transaction for UniverseTransaction { - type CommitCheck = UniverseCommitCheck; + type CommitCheck = impl fmt::Debug; type Output = transaction::NoOutput; fn check(&self, target: &Universe) -> Result { @@ -438,7 +449,7 @@ impl Transaction for UniverseTransaction { } impl Merge for UniverseTransaction { - type MergeCheck = UniverseMergeCheck; + type MergeCheck = impl fmt::Debug; type Conflict = UniverseConflict; fn check_merge(&self, other: &Self) -> Result { @@ -466,10 +477,14 @@ impl Merge for UniverseTransaction { behaviors, universe_id, } = self; + let UniverseMergeCheck { + members: check_members, + behaviors: check_behaviors, + } = check; - members.commit_merge(other.members, check.members); + members.commit_merge(other.members, check_members); anonymous_insertions.extend(other.anonymous_insertions); - behaviors.commit_merge(other.behaviors, check.behaviors); + behaviors.commit_merge(other.behaviors, check_behaviors); transaction::merge_option( universe_id, other.universe_id,