aboutsummaryrefslogtreecommitdiff
path: root/CHANGELOG.md
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-06-07 19:42:02 +0800
committer魏曹先生 <1992414357@qq.com>2026-06-07 19:42:02 +0800
commit9725bbc5a41e00a2b952cdfe4a04d472765c9e41 (patch)
tree05ef878bb5b95e32713349eb82ed74665eb9bfa9 /CHANGELOG.md
parenta88a4478bfa9c18d49296460b98c0512f34794c4 (diff)
Add LazyRes for lazy resource initialization
Diffstat (limited to 'CHANGELOG.md')
-rw-r--r--CHANGELOG.md30
1 files changed, 30 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 95db724..bc74d21 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -39,6 +39,36 @@ program.with_setup(BasicProgramSetup);
3. **\[core\]** Added `verbose`, `quiet`, `debug`, `color`, and `progress` fields to `ProgramStdoutSetting`, and `dry_run`, `force`, `interactive`, and `assume_yes` fields to `ProgramUserContext`. These fields are annotated as conventions only, meaning the framework does not enforce any particular behavior — it is up to the application to read and act on them.
+4. **\[core\]** Added `LazyRes<T>` for lazy resource initialization. Resources wrapped in `LazyRes<T>` are only initialized when first accessed via `get_ref()` or `get_mut()`, rather than immediately when added to the program. This is useful for resources that are expensive to initialize and may not always be needed.
+
+```rust
+use std::collections::BTreeMap;
+use mingling::{LazyInit, LazyRes, prelude::*};
+
+#[derive(Default, Clone)]
+pub struct ResLargeData {
+ pub data: BTreeMap<String, String>,
+}
+
+fn init_res_large_data() -> ResLargeData {
+ // Expensive initialization here
+ ResLargeData { data: BTreeMap::new() }
+}
+
+fn main() {
+ let mut program = ThisProgram::new();
+ program.with_resource(ResLargeData::lazy_init(init_res_large_data));
+ // ...
+}
+
+// Injected as &mut LazyRes<T> instead of &T
+#[renderer]
+fn render_entry_show(_args: EntryShow, res: &mut LazyRes<ResLargeData>) {
+ let res = res.get_ref(); // Initialization happens here
+ // use res...
+}
+```
+
#### **BREAKING CHANGES** (API CHANGES):
1. **\[core\]** Changed the signature of `ProgramSetup::setup` from `fn setup(&mut self, program: &mut Program<C>) -> S` to `fn setup(self, program: &mut Program<C>)`, consuming `self` instead of taking a mutable reference. Correspondingly, `Program::with_setup` now accepts `S` by value (`&mut self, setup: S`) instead of by mutable reference (`&mut self, setup: &mut S`).