From 60a8baa2af48ac70d18d0586d086b41e62904a96 Mon Sep 17 00:00:00 2001 From: leudz Date: Sun, 9 Jun 2024 05:36:46 +0200 Subject: [PATCH] Make a few things public to enable users to create custom systems --- src/borrow/borrow_info.rs | 7 +++++++ src/borrow/mod.rs | 15 +++++++++++++++ src/scheduler/system.rs | 40 ++++++++++++++++++++++++--------------- src/type_id/mod.rs | 3 ++- 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/borrow/borrow_info.rs b/src/borrow/borrow_info.rs index b76f0028..5090d70c 100644 --- a/src/borrow/borrow_info.rs +++ b/src/borrow/borrow_info.rs @@ -12,6 +12,7 @@ use crate::error; use crate::scheduler::TypeInfo; use crate::sparse_set::SparseSet; use crate::storage::StorageId; +use crate::system::Nothing; use crate::tracking::{Track, Tracking}; use crate::unique::UniqueStorage; use crate::views::{ @@ -66,6 +67,12 @@ pub unsafe trait BorrowInfo { ); } +// this is needed for downstream crates to impl IntoWorkloadSystem +unsafe impl BorrowInfo for Nothing { + fn borrow_info(_: &mut Vec) {} + fn enable_tracking(_: &mut Vec Result<(), error::GetStorage>>) {} +} + unsafe impl BorrowInfo for () { fn borrow_info(_: &mut Vec) {} fn enable_tracking(_: &mut Vec Result<(), error::GetStorage>>) {} diff --git a/src/borrow/mod.rs b/src/borrow/mod.rs index 0b7e0549..8e353185 100644 --- a/src/borrow/mod.rs +++ b/src/borrow/mod.rs @@ -21,6 +21,7 @@ use crate::atomic_refcell::{ARef, ARefMut, SharedBorrow}; use crate::component::{Component, Unique}; use crate::error; use crate::sparse_set::SparseSet; +use crate::system::Nothing; use crate::tracking::{Track, Tracking, TrackingTimestamp}; use crate::unique::UniqueStorage; use crate::views::{EntitiesView, EntitiesViewMut, UniqueView, UniqueViewMut, View, ViewMut}; @@ -86,6 +87,20 @@ pub trait Borrow { ) -> Result, error::GetStorage>; } +// this is needed for downstream crate to impl System +impl Borrow for Nothing { + type View<'a> = (); + + fn borrow<'a>( + _all_storages: &'a AllStorages, + _all_borrow: Option>, + _last_run: Option, + _current: TrackingTimestamp, + ) -> Result, error::GetStorage> { + Ok(()) + } +} + impl Borrow for () { type View<'a> = (); diff --git a/src/scheduler/system.rs b/src/scheduler/system.rs index 0201956e..8a890058 100644 --- a/src/scheduler/system.rs +++ b/src/scheduler/system.rs @@ -35,22 +35,32 @@ use alloc::vec::Vec; /// [`Workload`]: crate::Workload #[allow(clippy::type_complexity)] pub struct WorkloadSystem { - #[doc(hidden)] - pub(crate) type_id: TypeId, - pub(crate) display_name: Box, - pub(crate) system_fn: Box Result<(), error::Run> + Send + Sync + 'static>, + #[allow(missing_docs)] + pub type_id: TypeId, + #[allow(missing_docs)] + pub display_name: Box, + #[allow(missing_docs)] + pub system_fn: Box Result<(), error::Run> + Send + Sync + 'static>, /// access information - pub(crate) borrow_constraints: Vec, - pub(crate) tracking_to_enable: Vec Result<(), error::GetStorage>>, - pub(crate) generator: Box) -> TypeId + Send + Sync + 'static>, - pub(crate) run_if: - Option Result + Send + Sync + 'static>>, - pub(crate) tags: Vec>, - pub(crate) before_all: DedupedLabels, - pub(crate) after_all: DedupedLabels, - pub(crate) require_in_workload: DedupedLabels, - pub(crate) require_before: DedupedLabels, - pub(crate) require_after: DedupedLabels, + pub borrow_constraints: Vec, + /// Generates the tracking to enable for this system's views + pub tracking_to_enable: Vec Result<(), error::GetStorage>>, + /// Generates constraints and system type id + pub generator: Box) -> TypeId + Send + Sync + 'static>, + #[allow(missing_docs)] + pub run_if: Option Result + Send + Sync + 'static>>, + #[allow(missing_docs)] + pub tags: Vec>, + #[allow(missing_docs)] + pub before_all: DedupedLabels, + #[allow(missing_docs)] + pub after_all: DedupedLabels, + #[allow(missing_docs)] + pub require_in_workload: DedupedLabels, + #[allow(missing_docs)] + pub require_before: DedupedLabels, + #[allow(missing_docs)] + pub require_after: DedupedLabels, } impl Extend for Workload { diff --git a/src/type_id/mod.rs b/src/type_id/mod.rs index 16cc6114..2f1b1d14 100644 --- a/src/type_id/mod.rs +++ b/src/type_id/mod.rs @@ -11,7 +11,8 @@ use core::hash::{Hash, Hasher}; pub struct TypeId(pub(crate) u128); impl TypeId { - pub(crate) fn of() -> Self { + /// Returns the `TypeId` of the type this generic function has been instantiated with. + pub fn of() -> Self { core::any::TypeId::of::().into() } #[cfg(test)]