aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-08-18 02:23:13 +0800
committer魏曹先生 <1992414357@qq.com>2026-08-18 02:23:13 +0800
commite70ffc81399f0f90f71fd269f4ba2ee90ca20c4a (patch)
tree0b963d536d6d6227f128397eb8d9f6ddc2c84163
parent559ad2e9ddec8c74ce2e922224392365101a7396 (diff)
chore!: simplify DirectoryEnvironmentSetup to unit struct
Remove the generic parameter `C` from `DirectoryEnvironmentSetup`, making it a unit struct that no longer requires `::<C>::default()` for construction. Update the `ProgramSetup` impl and the `setup` method signature accordingly, and improve the doc comments.
-rw-r--r--CHANGELOG.md19
-rw-r--r--mingling/src/setups/dirs.rs70
2 files changed, 62 insertions, 27 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 06c6b13..a3090b4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -458,6 +458,25 @@ None
8. **[`Cargo.toml`]** Removed the legacy `extra_macros` feature alias from `mingling/Cargo.toml`. The `extras` feature (introduced in 0.4.0, BREAKING CHANGE #1) is now the sole name for this feature; the deprecated alias is gone.
+9. **[`setups:dirs`]** **[BREAKING]** Simplified the `DirectoryEnvironmentSetup` type — it is no longer generic over the program collect type `C` and no longer requires `DirectoryEnvironmentSetup::<C>::default()` to construct.
+
+ ### What changed
+
+ Previously, `DirectoryEnvironmentSetup` was a generic struct `DirectoryEnvironmentSetup<C>` (carrying `PhantomData<C>`) that had to be constructed via `DirectoryEnvironmentSetup::<C>::default()` before calling `Program::with_setup`. Now the struct is unit-like (`pub struct DirectoryEnvironmentSetup;`), so it can be constructed directly as a value with no `::default()` call and no generic parameter.
+
+ Additionally, the `setup` method's `program` parameter was retyped from `crate::Program<C>` to `mingling_core::Program<C>` for cleanliness.
+
+ ### Removed / changed API
+ - **`DirectoryEnvironmentSetup<C>`** → **`DirectoryEnvironmentSetup`** — The struct no longer has a generic parameter (previously `DirectoryEnvironmentSetup<C>` with `PhantomData<C>`).
+ - **`impl<C> Default for DirectoryEnvironmentSetup<C>`** — Removed. The unit struct uses the derived/implicit `Default`, and more importantly construction is now just the plain value `DirectoryEnvironmentSetup`, not `DirectoryEnvironmentSetup::<C>::default()`.
+ - **`impl<C> ProgramSetup<C> for DirectoryEnvironmentSetup<C>`** → **`impl<C> ProgramSetup<C> for DirectoryEnvironmentSetup`** — The `ProgramSetup` impl is now on the unit type.
+
+ ### Migration guide
+ - Replace `program.with_setup(DirectoryEnvironmentSetup::<ThisProgram>::default())` with `program.with_setup(DirectoryEnvironmentSetup)`.
+ - Any type annotations referencing `DirectoryEnvironmentSetup<C>` must drop the generic argument.
+
+ _No behavioral changes — the setup still registers the same four directory resources (`ResCurrentDir`, `ResCurrentExe`, `ResHomeDir`, `ResTempDir`) in the program's resource store. The type simplification is purely ergonomic.
+
---
## Contents
diff --git a/mingling/src/setups/dirs.rs b/mingling/src/setups/dirs.rs
index ea7f282..65196c2 100644
--- a/mingling/src/setups/dirs.rs
+++ b/mingling/src/setups/dirs.rs
@@ -1,37 +1,53 @@
-// Doc Not Optimize
-use std::marker::PhantomData;
-
-use mingling_core::{ProgramCollect, setup::ProgramSetup};
+use mingling_core::{Program, ProgramCollect, setup::ProgramSetup};
use crate::res::{ResCurrentDir, ResCurrentExe, ResHomeDir, ResTempDir};
-/// Provides the ability to set up commonly used directory resources for the program.
-///
-/// This setup item registers the following directory resources in the program:
-/// - `ResCurrentDir`: Current working directory
-/// - `ResCurrentExe`: Directory containing the executable
-/// - `ResHomeDir`: User's home directory
-/// - `ResTempDir`: Temporary directory
-pub struct DirectoryEnvironmentSetup<C> {
- _collect: PhantomData<C>,
-}
-
-impl<C> Default for DirectoryEnvironmentSetup<C>
-where
- C: ProgramCollect<Enum = C> + 'static,
-{
- fn default() -> Self {
- Self {
- _collect: PhantomData,
- }
- }
-}
+/// `Directory Environment` Setup for managing common directory resources
+///
+/// This Setup registers commonly used directory resources into the program's
+/// resource store. It provides the current working directory, the executable's
+/// directory, the user's home directory, and the system's temporary directory,
+/// so that these paths can be retrieved from the resource store without
+/// recomputing them each time.
+///
+/// # Usage
+///
+/// This Setup can be registered using the
+/// [`Program`](https://docs.rs/mingling/latest/mingling/struct.Program.html)
+/// `with_setup` method, for example:
+///
+/// ```rust
+/// # use mingling::MockProgramCollect as ThisProgram;
+/// use mingling::Program;
+/// use mingling::setup::DirectoryEnvironmentSetup;
+///
+/// let mut program = Program::<ThisProgram>::new();
+/// program.with_setup(DirectoryEnvironmentSetup);
+/// ```
+///
+/// # Behavior
+///
+/// - Registers an [`ResCurrentDir`] resource containing the current working
+/// directory.
+/// - Registers an [`ResCurrentExe`] resource containing the directory of the
+/// currently running executable.
+/// - Registers an [`ResHomeDir`] resource containing the user's home directory.
+/// - Registers an [`ResTempDir`] resource containing the system's temporary
+/// directory.
+///
+/// # Notes
+///
+/// - All directory values are resolved at setup time and stored in the
+/// resource store.
+/// - These resources can be retrieved later using the program's `resource`
+/// accessor with the corresponding resource type.
+pub struct DirectoryEnvironmentSetup;
-impl<C> ProgramSetup<C> for DirectoryEnvironmentSetup<C>
+impl<C> ProgramSetup<C> for DirectoryEnvironmentSetup
where
C: ProgramCollect<Enum = C> + 'static,
{
- fn setup(self, program: &mut crate::Program<C>) {
+ fn setup(self, program: &mut Program<C>) {
program.with_resource(ResCurrentDir::default());
program.with_resource(ResCurrentExe::default());
program.with_resource(ResHomeDir::default());