qubit_function/suppliers/supplier.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2025 - 2026.
4 * Haixing Hu, Qubit Co. Ltd.
5 *
6 * All rights reserved.
7 *
8 ******************************************************************************/
9//! # Read-only Supplier Types
10//!
11//! Provides read-only supplier implementations that generate and
12//! return values without modifying their own state.
13//!
14//! # Overview
15//!
16//! A **Supplier** is a functional abstraction that
17//! generates values without accepting input or modifying its own
18//! state. Unlike `Supplier`, it uses `&self` instead of `&mut
19//! self`, enabling usage in read-only contexts and lock-free
20//! concurrent access.
21//!
22//! # Key Differences from Supplier
23//!
24//! | Aspect | Supplier | Supplier |
25//! |--------|----------|------------------|
26//! | self signature | `&mut self` | `&self` |
27//! | Closure type | `FnMut() -> T` | `Fn() -> T` |
28//! | Can modify state | Yes | No |
29//! | Arc implementation | `Arc<Mutex<FnMut>>` | `Arc<Fn>` (lock-free!) |
30//! | Use cases | Counter, generator | Factory, constant, high concurrency |
31//!
32//! # Three Implementations
33//!
34//! - **`BoxSupplier<T>`**: Single ownership using `Box<dyn
35//! Fn() -> T>`. Zero overhead, cannot be cloned. Best for
36//! one-time use in read-only contexts.
37//!
38//! - **`ArcSupplier<T>`**: Thread-safe shared ownership
39//! using `Arc<dyn Fn() -> T + Send + Sync>`. **Lock-free** - no
40//! Mutex needed! Can be cloned and sent across threads with
41//! excellent performance.
42//!
43//! - **`RcSupplier<T>`**: Single-threaded shared ownership
44//! using `Rc<dyn Fn() -> T>`. Can be cloned but not sent across
45//! threads. Lightweight alternative to `ArcSupplier`.
46//!
47//! # Use Cases
48//!
49//! ## 1. Calling in `&self` Methods
50//!
51//! ```rust
52//! use qubit_function::{ArcSupplier, Supplier};
53//!
54//! struct Executor<E> {
55//! error_supplier: ArcSupplier<E>,
56//! }
57//!
58//! impl<E> Executor<E> {
59//! fn execute(&self) -> Result<(), E> {
60//! // Can call directly in &self method!
61//! Err(self.error_supplier.get())
62//! }
63//! }
64//! ```
65//!
66//! ## 2. High-Concurrency Lock-Free Access
67//!
68//! ```rust
69//! use qubit_function::{ArcSupplier, Supplier};
70//! use std::thread;
71//!
72//! let factory = ArcSupplier::new(|| {
73//! String::from("Hello, World!")
74//! });
75//!
76//! let handles: Vec<_> = (0..10)
77//! .map(|_| {
78//! let f = factory.clone();
79//! thread::spawn(move || f.get()) // Lock-free!
80//! })
81//! .collect();
82//!
83//! for h in handles {
84//! assert_eq!(h.join().unwrap(), "Hello, World!");
85//! }
86//! ```
87//!
88//! ## 3. Fixed Factories
89//!
90//! ```rust
91//! use qubit_function::{BoxSupplier, Supplier};
92//!
93//! #[derive(Clone)]
94//! struct Config {
95//! timeout: u64,
96//! }
97//!
98//! let config_factory = BoxSupplier::new(|| Config {
99//! timeout: 30,
100//! });
101//!
102//! assert_eq!(config_factory.get().timeout, 30);
103//! assert_eq!(config_factory.get().timeout, 30);
104//! ```
105//!
106//! # Performance Comparison
107//!
108//! For stateless scenarios in multi-threaded environments:
109//!
110//! - `ArcSupplier<T>`: Requires `Mutex`, lock contention on
111//! every `get()` call
112//! - `ArcSupplier<T>`: Lock-free, can call `get()`
113//! concurrently without contention
114//!
115//! Benchmark results show `ArcSupplier` can be **10x
116//! faster** than `ArcSupplier` in high-concurrency scenarios.
117//!
118//! # Author
119//!
120//! Haixing Hu
121
122use std::rc::Rc;
123use std::sync::Arc;
124
125use crate::macros::{
126 impl_arc_conversions,
127 impl_box_conversions,
128 impl_closure_trait,
129 impl_rc_conversions,
130};
131use crate::predicates::predicate::Predicate;
132use crate::suppliers::macros::{
133 impl_box_supplier_methods,
134 impl_shared_supplier_methods,
135 impl_supplier_clone,
136 impl_supplier_common_methods,
137 impl_supplier_debug_display,
138};
139use crate::transformers::transformer::Transformer;
140use crate::BoxSupplierOnce;
141
142// ======================================================================
143// Supplier Trait
144// ======================================================================
145
146/// Read-only supplier trait: generates values without modifying
147/// state.
148///
149/// The core abstraction for stateless value generation. Unlike
150/// `Supplier<T>`, it uses `&self` instead of `&mut self`, enabling
151/// usage in read-only contexts and lock-free concurrent access.
152///
153/// # Key Characteristics
154///
155/// - **No input parameters**: Pure value generation
156/// - **Read-only access**: Uses `&self`, doesn't modify state
157/// - **Returns ownership**: Returns `T` (not `&T`) to avoid
158/// lifetime issues
159/// - **Lock-free concurrency**: `Arc` implementation doesn't need
160/// `Mutex`
161///
162/// # Automatically Implemented for Closures
163///
164/// All `Fn() -> T` closures automatically implement this trait,
165/// enabling seamless integration with both raw closures and
166/// wrapped supplier types.
167///
168/// # Examples
169///
170/// ## Using with Generic Functions
171///
172/// ```rust
173/// use qubit_function::{Supplier, BoxSupplier};
174///
175/// fn call_twice<S: Supplier<i32>>(supplier: &S)
176/// -> (i32, i32)
177/// {
178/// (supplier.get(), supplier.get())
179/// }
180///
181/// let s = BoxSupplier::new(|| 42);
182/// assert_eq!(call_twice(&s), (42, 42));
183///
184/// let closure = || 100;
185/// assert_eq!(call_twice(&closure), (100, 100));
186/// ```
187///
188/// ## Stateless Factory
189///
190/// ```rust
191/// use qubit_function::Supplier;
192///
193/// struct User {
194/// name: String,
195/// }
196///
197/// impl User {
198/// fn new() -> Self {
199/// User {
200/// name: String::from("Default"),
201/// }
202/// }
203/// }
204///
205/// let factory = || User::new();
206/// let user1 = factory.get();
207/// let user2 = factory.get();
208/// // Each call creates a new User instance
209/// ```
210///
211/// # Author
212///
213/// Haixing Hu
214pub trait Supplier<T> {
215 /// Generates and returns a value.
216 ///
217 /// Executes the underlying function and returns the generated
218 /// value. Uses `&self` because the supplier doesn't modify its
219 /// own state.
220 ///
221 /// # Returns
222 ///
223 /// The generated value of type `T`
224 ///
225 /// # Examples
226 ///
227 /// ```rust
228 /// use qubit_function::{Supplier, BoxSupplier};
229 ///
230 /// let supplier = BoxSupplier::new(|| 42);
231 /// assert_eq!(supplier.get(), 42);
232 /// assert_eq!(supplier.get(), 42);
233 /// ```
234 fn get(&self) -> T;
235
236 /// Converts to `BoxSupplier`.
237 ///
238 /// This method has a default implementation that wraps the
239 /// supplier in a `BoxSupplier`. Custom implementations
240 /// can override this method for optimization purposes.
241 ///
242 /// # Returns
243 ///
244 /// A new `BoxSupplier<T>` instance
245 ///
246 /// # Examples
247 ///
248 /// ```rust
249 /// use qubit_function::Supplier;
250 ///
251 /// let closure = || 42;
252 /// let boxed = closure.into_box();
253 /// assert_eq!(boxed.get(), 42);
254 /// ```
255 fn into_box(self) -> BoxSupplier<T>
256 where
257 Self: Sized + 'static,
258 {
259 BoxSupplier::new(move || self.get())
260 }
261
262 /// Converts to `RcSupplier`.
263 ///
264 /// This method has a default implementation that wraps the
265 /// supplier in an `RcSupplier`. Custom implementations
266 /// can override this method for optimization purposes.
267 ///
268 /// # Returns
269 ///
270 /// A new `RcSupplier<T>` instance
271 ///
272 /// # Examples
273 ///
274 /// ```rust
275 /// use qubit_function::Supplier;
276 ///
277 /// let closure = || 42;
278 /// let rc = closure.into_rc();
279 /// assert_eq!(rc.get(), 42);
280 /// ```
281 fn into_rc(self) -> RcSupplier<T>
282 where
283 Self: Sized + 'static,
284 {
285 RcSupplier::new(move || self.get())
286 }
287
288 /// Converts to `ArcSupplier`.
289 ///
290 /// This method has a default implementation that wraps the
291 /// supplier in an `ArcSupplier`. Custom implementations
292 /// can override this method for optimization purposes.
293 ///
294 /// # Returns
295 ///
296 /// A new `ArcSupplier<T>` instance
297 ///
298 /// # Examples
299 ///
300 /// ```rust
301 /// use qubit_function::Supplier;
302 ///
303 /// let closure = || 42;
304 /// let arc = closure.into_arc();
305 /// assert_eq!(arc.get(), 42);
306 /// ```
307 fn into_arc(self) -> ArcSupplier<T>
308 where
309 Self: Sized + Send + Sync + 'static,
310 {
311 ArcSupplier::new(move || self.get())
312 }
313
314 /// Converts to a closure implementing `Fn() -> T`.
315 ///
316 /// This method has a default implementation that wraps the
317 /// supplier in a closure. Custom implementations can override
318 /// this method for optimization purposes.
319 ///
320 /// # Returns
321 ///
322 /// A closure implementing `Fn() -> T`
323 ///
324 /// # Examples
325 ///
326 /// ```rust
327 /// use qubit_function::Supplier;
328 ///
329 /// let closure = || 42;
330 /// let fn_closure = closure.into_fn();
331 /// assert_eq!(fn_closure(), 42);
332 /// assert_eq!(fn_closure(), 42);
333 /// ```
334 fn into_fn(self) -> impl Fn() -> T
335 where
336 Self: Sized + 'static,
337 {
338 move || self.get()
339 }
340
341 /// Converts to `BoxSupplierOnce`.
342 ///
343 /// This method has a default implementation that wraps the
344 /// supplier in a `BoxSupplierOnce`. Custom implementations
345 /// can override this method for optimization purposes.
346 ///
347 /// # Returns
348 ///
349 /// A new `BoxSupplierOnce<T>` instance
350 ///
351 /// # Examples
352 ///
353 /// ```rust
354 /// use qubit_function::Supplier;
355 ///
356 /// let closure = || 42;
357 /// let once = closure.into_once();
358 /// assert_eq!(once.get(), 42);
359 /// ```
360 fn into_once(self) -> BoxSupplierOnce<T>
361 where
362 Self: Sized + 'static,
363 {
364 BoxSupplierOnce::new(move || self.get())
365 }
366
367 /// Converts to `BoxSupplier` by cloning.
368 ///
369 /// This method clones the supplier and wraps it in a
370 /// `BoxSupplier`. Requires `Self: Clone`. Custom
371 /// implementations can override this method for optimization.
372 ///
373 /// # Returns
374 ///
375 /// A new `BoxSupplier<T>` instance
376 ///
377 /// # Examples
378 ///
379 /// ```rust
380 /// use qubit_function::Supplier;
381 ///
382 /// let closure = || 42;
383 /// let boxed = closure.to_box();
384 /// assert_eq!(boxed.get(), 42);
385 /// ```
386 fn to_box(&self) -> BoxSupplier<T>
387 where
388 Self: Clone + 'static,
389 {
390 self.clone().into_box()
391 }
392
393 /// Converts to `RcSupplier` by cloning.
394 ///
395 /// This method clones the supplier and wraps it in an
396 /// `RcSupplier`. Requires `Self: Clone`. Custom
397 /// implementations can override this method for optimization.
398 ///
399 /// # Returns
400 ///
401 /// A new `RcSupplier<T>` instance
402 ///
403 /// # Examples
404 ///
405 /// ```rust
406 /// use qubit_function::Supplier;
407 ///
408 /// let closure = || 42;
409 /// let rc = closure.to_rc();
410 /// assert_eq!(rc.get(), 42);
411 /// ```
412 fn to_rc(&self) -> RcSupplier<T>
413 where
414 Self: Clone + 'static,
415 {
416 self.clone().into_rc()
417 }
418
419 /// Converts to `ArcSupplier` by cloning.
420 ///
421 /// This method clones the supplier and wraps it in an
422 /// `ArcSupplier`. Requires `Self: Clone + Send + Sync`.
423 /// Custom implementations can override this method for
424 /// optimization.
425 ///
426 /// # Returns
427 ///
428 /// A new `ArcSupplier<T>` instance
429 ///
430 /// # Examples
431 ///
432 /// ```rust
433 /// use qubit_function::Supplier;
434 ///
435 /// let closure = || 42;
436 /// let arc = closure.to_arc();
437 /// assert_eq!(arc.get(), 42);
438 /// ```
439 fn to_arc(&self) -> ArcSupplier<T>
440 where
441 Self: Clone + Send + Sync + 'static,
442 {
443 self.clone().into_arc()
444 }
445
446 /// Converts to a closure by cloning.
447 ///
448 /// This method clones the supplier and wraps it in a closure
449 /// implementing `Fn() -> T`. Requires `Self: Clone`. Custom
450 /// implementations can override this method for optimization.
451 ///
452 /// # Returns
453 ///
454 /// A closure implementing `Fn() -> T`
455 ///
456 /// # Examples
457 ///
458 /// ```rust
459 /// use qubit_function::Supplier;
460 ///
461 /// let closure = || 42;
462 /// let fn_closure = closure.to_fn();
463 /// assert_eq!(fn_closure(), 42);
464 /// assert_eq!(fn_closure(), 42);
465 /// ```
466 fn to_fn(&self) -> impl Fn() -> T
467 where
468 Self: Clone + 'static,
469 {
470 self.clone().into_fn()
471 }
472
473 /// Converts to `BoxSupplierOnce` without consuming self
474 ///
475 /// **⚠️ Requires Clone**: This method requires `Self` to implement `Clone`.
476 /// Clones the current supplier and converts the clone to a one-time supplier.
477 ///
478 /// # Returns
479 ///
480 /// Returns a `BoxSupplierOnce<T>`
481 fn to_once(&self) -> BoxSupplierOnce<T>
482 where
483 Self: Clone + 'static,
484 {
485 self.clone().into_once()
486 }
487}
488
489// ======================================================================
490// BoxSupplier - Single Ownership Implementation
491// ======================================================================
492
493/// Box-based single ownership read-only supplier.
494///
495/// Uses `Box<dyn Fn() -> T>` for single ownership scenarios. This
496/// is the most lightweight read-only supplier with zero reference
497/// counting overhead.
498///
499/// # Ownership Model
500///
501/// Methods consume `self` (move semantics) or borrow `&self` for
502/// read-only operations. When you call methods like `map()`, the
503/// original supplier is consumed and you get a new one:
504///
505/// ```rust
506/// use qubit_function::{BoxSupplier, Supplier};
507///
508/// let supplier = BoxSupplier::new(|| 10);
509/// let mapped = supplier.map(|x| x * 2);
510/// // supplier is no longer usable here
511/// ```
512///
513/// # Examples
514///
515/// ## Constant Factory
516///
517/// ```rust
518/// use qubit_function::{BoxSupplier, Supplier};
519///
520/// let factory = BoxSupplier::new(|| 42);
521/// assert_eq!(factory.get(), 42);
522/// assert_eq!(factory.get(), 42);
523/// ```
524///
525/// ## Method Chaining
526///
527/// ```rust
528/// use qubit_function::{BoxSupplier, Supplier};
529///
530/// let pipeline = BoxSupplier::new(|| 10)
531/// .map(|x| x * 2)
532/// .map(|x| x + 5);
533///
534/// assert_eq!(pipeline.get(), 25);
535/// ```
536///
537/// # Author
538///
539/// Haixing Hu
540pub struct BoxSupplier<T> {
541 function: Box<dyn Fn() -> T>,
542 name: Option<String>,
543}
544
545impl<T> BoxSupplier<T> {
546 // Generates: new(), new_with_name(), name(), set_name(), constant()
547 impl_supplier_common_methods!(BoxSupplier<T>, (Fn() -> T + 'static), |f| Box::new(f));
548
549 // Generates: map(), filter(), zip()
550 impl_box_supplier_methods!(BoxSupplier<T>, Supplier);
551}
552
553// Generates: Debug and Display implementations for BoxSupplier<T>
554impl_supplier_debug_display!(BoxSupplier<T>);
555
556impl<T> Supplier<T> for BoxSupplier<T> {
557 fn get(&self) -> T {
558 (self.function)()
559 }
560
561 // Generates: into_box(), into_rc(), into_fn(), into_once()
562 impl_box_conversions!(
563 BoxSupplier<T>,
564 RcSupplier,
565 Fn() -> T,
566 BoxSupplierOnce
567 );
568}
569
570// ======================================================================
571// ArcSupplier - Thread-safe Shared Ownership Implementation
572// ======================================================================
573
574/// Thread-safe shared ownership read-only supplier.
575///
576/// Uses `Arc<dyn Fn() -> T + Send + Sync>` for thread-safe shared
577/// ownership. **Lock-free** - no `Mutex` needed! Can be cloned and
578/// sent across threads with excellent concurrent performance.
579///
580/// # Ownership Model
581///
582/// Methods borrow `&self` instead of consuming `self`. The
583/// original supplier remains usable after method calls:
584///
585/// ```rust
586/// use qubit_function::{ArcSupplier, Supplier};
587///
588/// let source = ArcSupplier::new(|| 10);
589/// let mapped = source.map(|x| x * 2);
590/// // source is still usable here!
591/// ```
592///
593/// # Lock-Free Performance
594///
595/// Unlike `ArcSupplier`, this implementation doesn't need `Mutex`.
596/// Multiple threads can call `get()` concurrently without lock
597/// contention, making it ideal for high-concurrency scenarios.
598///
599/// # Examples
600///
601/// ## Thread-safe Factory
602///
603/// ```rust
604/// use qubit_function::{ArcSupplier, Supplier};
605/// use std::thread;
606///
607/// let factory = ArcSupplier::new(|| {
608/// String::from("Hello")
609/// });
610///
611/// let f1 = factory.clone();
612/// let f2 = factory.clone();
613///
614/// let h1 = thread::spawn(move || f1.get());
615/// let h2 = thread::spawn(move || f2.get());
616///
617/// assert_eq!(h1.join().unwrap(), "Hello");
618/// assert_eq!(h2.join().unwrap(), "Hello");
619/// ```
620///
621/// ## Reusable Transformations
622///
623/// ```rust
624/// use qubit_function::{ArcSupplier, Supplier};
625///
626/// let base = ArcSupplier::new(|| 10);
627/// let doubled = base.map(|x| x * 2);
628/// let tripled = base.map(|x| x * 3);
629///
630/// // All remain usable
631/// assert_eq!(base.get(), 10);
632/// assert_eq!(doubled.get(), 20);
633/// assert_eq!(tripled.get(), 30);
634/// ```
635///
636/// # Author
637///
638/// Haixing Hu
639pub struct ArcSupplier<T> {
640 function: Arc<dyn Fn() -> T + Send + Sync>,
641 name: Option<String>,
642}
643
644impl<T> ArcSupplier<T> {
645 // Generates: new(), new_with_name(), name(), set_name()
646 // Note: constant() is NOT generated here, implemented separately below
647 crate::macros::impl_common_new_methods!(
648 (Fn() -> T + Send + Sync + 'static),
649 |f| Arc::new(f),
650 "supplier"
651 );
652
653 crate::macros::impl_common_name_methods!("supplier");
654
655 // Generates: map(), filter(), zip()
656 impl_shared_supplier_methods!(ArcSupplier<T>, Supplier, (arc));
657}
658
659// Separate impl block for constant() with stricter T: Sync bound
660impl<T> ArcSupplier<T> {
661 /// Creates a supplier that returns a constant value.
662 ///
663 /// Creates a supplier that always returns the same value. Useful for
664 /// default values or placeholder implementations.
665 ///
666 /// **Note:** This method requires `T: Sync` because the constant value
667 /// is captured by a `Fn` closure which needs to be `Sync` for `Arc`.
668 ///
669 /// # Parameters
670 ///
671 /// * `value` - The constant value to return
672 ///
673 /// # Returns
674 ///
675 /// Returns a new supplier instance that returns the constant value.
676 ///
677 /// # Examples
678 ///
679 /// ```rust
680 /// use qubit_function::{ArcSupplier, Supplier};
681 ///
682 /// let supplier = ArcSupplier::constant(42);
683 /// assert_eq!(supplier.get(), 42);
684 /// assert_eq!(supplier.get(), 42); // Can be called multiple times
685 /// ```
686 pub fn constant(value: T) -> Self
687 where
688 T: Clone + Send + Sync + 'static,
689 {
690 Self::new(move || value.clone())
691 }
692}
693
694// Generates: Debug and Display implementations for ArcSupplier<T>
695impl_supplier_debug_display!(ArcSupplier<T>);
696
697// Generates: Clone implementation for ArcSupplier<T>
698impl_supplier_clone!(ArcSupplier<T>);
699
700impl<T> Supplier<T> for ArcSupplier<T> {
701 fn get(&self) -> T {
702 (self.function)()
703 }
704
705 // Use macro to implement conversion methods
706 impl_arc_conversions!(
707 ArcSupplier<T>,
708 BoxSupplier,
709 RcSupplier,
710 BoxSupplierOnce,
711 Fn() -> T
712 );
713}
714
715// ======================================================================
716// RcSupplier - Single-threaded Shared Ownership
717// ======================================================================
718
719/// Single-threaded shared ownership read-only supplier.
720///
721/// Uses `Rc<dyn Fn() -> T>` for single-threaded shared ownership.
722/// Can be cloned but not sent across threads.
723///
724/// # Ownership Model
725///
726/// Like `ArcSupplier`, methods borrow `&self` instead of
727/// consuming `self`:
728///
729/// ```rust
730/// use qubit_function::{RcSupplier, Supplier};
731///
732/// let source = RcSupplier::new(|| 10);
733/// let mapped = source.map(|x| x * 2);
734/// // source is still usable here!
735/// ```
736///
737/// # Examples
738///
739/// ## Shared Factory
740///
741/// ```rust
742/// use qubit_function::{RcSupplier, Supplier};
743///
744/// let factory = RcSupplier::new(|| {
745/// String::from("Hello")
746/// });
747///
748/// let f1 = factory.clone();
749/// let f2 = factory.clone();
750/// assert_eq!(f1.get(), "Hello");
751/// assert_eq!(f2.get(), "Hello");
752/// ```
753///
754/// ## Reusable Transformations
755///
756/// ```rust
757/// use qubit_function::{RcSupplier, Supplier};
758///
759/// let base = RcSupplier::new(|| 10);
760/// let doubled = base.map(|x| x * 2);
761/// let tripled = base.map(|x| x * 3);
762///
763/// assert_eq!(base.get(), 10);
764/// assert_eq!(doubled.get(), 20);
765/// assert_eq!(tripled.get(), 30);
766/// ```
767///
768/// # Author
769///
770/// Haixing Hu
771pub struct RcSupplier<T> {
772 function: Rc<dyn Fn() -> T>,
773 name: Option<String>,
774}
775
776impl<T> RcSupplier<T> {
777 // Generates: new(), new_with_name(), name(), set_name(), constant()
778 impl_supplier_common_methods!(RcSupplier<T>, (Fn() -> T + 'static), |f| Rc::new(f));
779
780 // Generates: map(), filter(), zip()
781 impl_shared_supplier_methods!(
782 RcSupplier<T>,
783 Supplier,
784 ('static)
785 );
786}
787
788// Generates: Debug and Display implementations for RcSupplier<T>
789impl_supplier_debug_display!(RcSupplier<T>);
790
791// Generates: Clone implementation for RcSupplier<T>
792impl_supplier_clone!(RcSupplier<T>);
793
794impl<T> Supplier<T> for RcSupplier<T> {
795 fn get(&self) -> T {
796 (self.function)()
797 }
798
799 // Generate all conversion methods using the unified macro
800 impl_rc_conversions!(
801 RcSupplier<T>,
802 BoxSupplier,
803 BoxSupplierOnce,
804 Fn() -> T
805 );
806}
807
808// ======================================================================
809// Implement Supplier for Closures
810// ======================================================================
811
812// Implement Supplier<T> for any type that implements Fn() -> T
813impl_closure_trait!(
814 Supplier<T>,
815 get,
816 BoxSupplierOnce,
817 Fn() -> T
818);
819
820// ======================================================================
821// Note on Extension Traits for Closures
822// ======================================================================
823//
824// We don't provide `FnSupplierOps` trait for `Fn() -> T` closures
825// because:
826//
827// 1. All `Fn` closures also implement `FnMut`, so they can use `FnSupplierOps`
828// from the `supplier` module
829// 2. Providing both would cause ambiguity errors due to overlapping trait impls
830// 3. Rust doesn't support negative trait bounds to exclude `FnMut`
831//
832// Users of `Fn` closures should use `FnSupplierOps` from `supplier` module,
833// or explicitly convert to `BoxSupplier` using `.into_box()` first.