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 T: 'static,
259 {
260 BoxSupplier::new(move || self.get())
261 }
262
263 /// Converts to `RcSupplier`.
264 ///
265 /// This method has a default implementation that wraps the
266 /// supplier in an `RcSupplier`. Custom implementations
267 /// can override this method for optimization purposes.
268 ///
269 /// # Returns
270 ///
271 /// A new `RcSupplier<T>` instance
272 ///
273 /// # Examples
274 ///
275 /// ```rust
276 /// use qubit_function::Supplier;
277 ///
278 /// let closure = || 42;
279 /// let rc = closure.into_rc();
280 /// assert_eq!(rc.get(), 42);
281 /// ```
282 fn into_rc(self) -> RcSupplier<T>
283 where
284 Self: Sized + 'static,
285 T: 'static,
286 {
287 RcSupplier::new(move || self.get())
288 }
289
290 /// Converts to `ArcSupplier`.
291 ///
292 /// This method has a default implementation that wraps the
293 /// supplier in an `ArcSupplier`. Custom implementations
294 /// can override this method for optimization purposes.
295 ///
296 /// # Returns
297 ///
298 /// A new `ArcSupplier<T>` instance
299 ///
300 /// # Examples
301 ///
302 /// ```rust
303 /// use qubit_function::Supplier;
304 ///
305 /// let closure = || 42;
306 /// let arc = closure.into_arc();
307 /// assert_eq!(arc.get(), 42);
308 /// ```
309 fn into_arc(self) -> ArcSupplier<T>
310 where
311 Self: Sized + Send + Sync + 'static,
312 T: 'static,
313 {
314 ArcSupplier::new(move || self.get())
315 }
316
317 /// Converts to a closure implementing `Fn() -> T`.
318 ///
319 /// This method has a default implementation that wraps the
320 /// supplier in a closure. Custom implementations can override
321 /// this method for optimization purposes.
322 ///
323 /// # Returns
324 ///
325 /// A closure implementing `Fn() -> T`
326 ///
327 /// # Examples
328 ///
329 /// ```rust
330 /// use qubit_function::Supplier;
331 ///
332 /// let closure = || 42;
333 /// let fn_closure = closure.into_fn();
334 /// assert_eq!(fn_closure(), 42);
335 /// assert_eq!(fn_closure(), 42);
336 /// ```
337 fn into_fn(self) -> impl Fn() -> T
338 where
339 Self: Sized + 'static,
340 {
341 move || self.get()
342 }
343
344 /// Converts to `BoxSupplierOnce`.
345 ///
346 /// This method has a default implementation that wraps the
347 /// supplier in a `BoxSupplierOnce`. Custom implementations
348 /// can override this method for optimization purposes.
349 ///
350 /// # Returns
351 ///
352 /// A new `BoxSupplierOnce<T>` instance
353 ///
354 /// # Examples
355 ///
356 /// ```rust
357 /// use qubit_function::Supplier;
358 ///
359 /// let closure = || 42;
360 /// let once = closure.into_once();
361 /// assert_eq!(once.get(), 42);
362 /// ```
363 fn into_once(self) -> BoxSupplierOnce<T>
364 where
365 Self: Sized + 'static,
366 T: 'static,
367 {
368 BoxSupplierOnce::new(move || self.get())
369 }
370
371 /// Converts to `BoxSupplier` by cloning.
372 ///
373 /// This method clones the supplier and wraps it in a
374 /// `BoxSupplier`. Requires `Self: Clone`. Custom
375 /// implementations can override this method for optimization.
376 ///
377 /// # Returns
378 ///
379 /// A new `BoxSupplier<T>` instance
380 ///
381 /// # Examples
382 ///
383 /// ```rust
384 /// use qubit_function::Supplier;
385 ///
386 /// let closure = || 42;
387 /// let boxed = closure.to_box();
388 /// assert_eq!(boxed.get(), 42);
389 /// ```
390 fn to_box(&self) -> BoxSupplier<T>
391 where
392 Self: Clone + 'static,
393 T: 'static,
394 {
395 self.clone().into_box()
396 }
397
398 /// Converts to `RcSupplier` by cloning.
399 ///
400 /// This method clones the supplier and wraps it in an
401 /// `RcSupplier`. Requires `Self: Clone`. Custom
402 /// implementations can override this method for optimization.
403 ///
404 /// # Returns
405 ///
406 /// A new `RcSupplier<T>` instance
407 ///
408 /// # Examples
409 ///
410 /// ```rust
411 /// use qubit_function::Supplier;
412 ///
413 /// let closure = || 42;
414 /// let rc = closure.to_rc();
415 /// assert_eq!(rc.get(), 42);
416 /// ```
417 fn to_rc(&self) -> RcSupplier<T>
418 where
419 Self: Clone + 'static,
420 T: 'static,
421 {
422 self.clone().into_rc()
423 }
424
425 /// Converts to `ArcSupplier` by cloning.
426 ///
427 /// This method clones the supplier and wraps it in an
428 /// `ArcSupplier`. Requires `Self: Clone + Send + Sync`.
429 /// Custom implementations can override this method for
430 /// optimization.
431 ///
432 /// # Returns
433 ///
434 /// A new `ArcSupplier<T>` instance
435 ///
436 /// # Examples
437 ///
438 /// ```rust
439 /// use qubit_function::Supplier;
440 ///
441 /// let closure = || 42;
442 /// let arc = closure.to_arc();
443 /// assert_eq!(arc.get(), 42);
444 /// ```
445 fn to_arc(&self) -> ArcSupplier<T>
446 where
447 Self: Clone + Send + Sync + 'static,
448 T: 'static,
449 {
450 self.clone().into_arc()
451 }
452
453 /// Converts to a closure by cloning.
454 ///
455 /// This method clones the supplier and wraps it in a closure
456 /// implementing `Fn() -> T`. Requires `Self: Clone`. Custom
457 /// implementations can override this method for optimization.
458 ///
459 /// # Returns
460 ///
461 /// A closure implementing `Fn() -> T`
462 ///
463 /// # Examples
464 ///
465 /// ```rust
466 /// use qubit_function::Supplier;
467 ///
468 /// let closure = || 42;
469 /// let fn_closure = closure.to_fn();
470 /// assert_eq!(fn_closure(), 42);
471 /// assert_eq!(fn_closure(), 42);
472 /// ```
473 fn to_fn(&self) -> impl Fn() -> T
474 where
475 Self: Clone + 'static,
476 {
477 self.clone().into_fn()
478 }
479
480 /// Converts to `BoxSupplierOnce` without consuming self
481 ///
482 /// **⚠️ Requires Clone**: This method requires `Self` to implement `Clone`.
483 /// Clones the current supplier and converts the clone to a one-time supplier.
484 ///
485 /// # Returns
486 ///
487 /// Returns a `BoxSupplierOnce<T>`
488 fn to_once(&self) -> BoxSupplierOnce<T>
489 where
490 Self: Clone + 'static,
491 T: 'static,
492 {
493 self.clone().into_once()
494 }
495}
496
497// ======================================================================
498// BoxSupplier - Single Ownership Implementation
499// ======================================================================
500
501/// Box-based single ownership read-only supplier.
502///
503/// Uses `Box<dyn Fn() -> T>` for single ownership scenarios. This
504/// is the most lightweight read-only supplier with zero reference
505/// counting overhead.
506///
507/// # Ownership Model
508///
509/// Methods consume `self` (move semantics) or borrow `&self` for
510/// read-only operations. When you call methods like `map()`, the
511/// original supplier is consumed and you get a new one:
512///
513/// ```rust
514/// use qubit_function::{BoxSupplier, Supplier};
515///
516/// let supplier = BoxSupplier::new(|| 10);
517/// let mapped = supplier.map(|x| x * 2);
518/// // supplier is no longer usable here
519/// ```
520///
521/// # Examples
522///
523/// ## Constant Factory
524///
525/// ```rust
526/// use qubit_function::{BoxSupplier, Supplier};
527///
528/// let factory = BoxSupplier::new(|| 42);
529/// assert_eq!(factory.get(), 42);
530/// assert_eq!(factory.get(), 42);
531/// ```
532///
533/// ## Method Chaining
534///
535/// ```rust
536/// use qubit_function::{BoxSupplier, Supplier};
537///
538/// let pipeline = BoxSupplier::new(|| 10)
539/// .map(|x| x * 2)
540/// .map(|x| x + 5);
541///
542/// assert_eq!(pipeline.get(), 25);
543/// ```
544///
545/// # Author
546///
547/// Haixing Hu
548pub struct BoxSupplier<T> {
549 function: Box<dyn Fn() -> T>,
550 name: Option<String>,
551}
552
553impl<T> BoxSupplier<T> {
554 // Generates: new(), new_with_name(), name(), set_name(), constant()
555 impl_supplier_common_methods!(BoxSupplier<T>, (Fn() -> T + 'static), |f| Box::new(f));
556
557 // Generates: map(), filter(), zip()
558 impl_box_supplier_methods!(BoxSupplier<T>, Supplier);
559}
560
561// Generates: Debug and Display implementations for BoxSupplier<T>
562impl_supplier_debug_display!(BoxSupplier<T>);
563
564impl<T> Supplier<T> for BoxSupplier<T> {
565 fn get(&self) -> T {
566 (self.function)()
567 }
568
569 // Generates: into_box(), into_rc(), into_fn(), into_once()
570 impl_box_conversions!(
571 BoxSupplier<T>,
572 RcSupplier,
573 Fn() -> T,
574 BoxSupplierOnce
575 );
576}
577
578// ======================================================================
579// ArcSupplier - Thread-safe Shared Ownership Implementation
580// ======================================================================
581
582/// Thread-safe shared ownership read-only supplier.
583///
584/// Uses `Arc<dyn Fn() -> T + Send + Sync>` for thread-safe shared
585/// ownership. **Lock-free** - no `Mutex` needed! Can be cloned and
586/// sent across threads with excellent concurrent performance.
587///
588/// # Ownership Model
589///
590/// Methods borrow `&self` instead of consuming `self`. The
591/// original supplier remains usable after method calls:
592///
593/// ```rust
594/// use qubit_function::{ArcSupplier, Supplier};
595///
596/// let source = ArcSupplier::new(|| 10);
597/// let mapped = source.map(|x| x * 2);
598/// // source is still usable here!
599/// ```
600///
601/// # Lock-Free Performance
602///
603/// Unlike `ArcSupplier`, this implementation doesn't need `Mutex`.
604/// Multiple threads can call `get()` concurrently without lock
605/// contention, making it ideal for high-concurrency scenarios.
606///
607/// # Examples
608///
609/// ## Thread-safe Factory
610///
611/// ```rust
612/// use qubit_function::{ArcSupplier, Supplier};
613/// use std::thread;
614///
615/// let factory = ArcSupplier::new(|| {
616/// String::from("Hello")
617/// });
618///
619/// let f1 = factory.clone();
620/// let f2 = factory.clone();
621///
622/// let h1 = thread::spawn(move || f1.get());
623/// let h2 = thread::spawn(move || f2.get());
624///
625/// assert_eq!(h1.join().unwrap(), "Hello");
626/// assert_eq!(h2.join().unwrap(), "Hello");
627/// ```
628///
629/// ## Reusable Transformations
630///
631/// ```rust
632/// use qubit_function::{ArcSupplier, Supplier};
633///
634/// let base = ArcSupplier::new(|| 10);
635/// let doubled = base.map(|x| x * 2);
636/// let tripled = base.map(|x| x * 3);
637///
638/// // All remain usable
639/// assert_eq!(base.get(), 10);
640/// assert_eq!(doubled.get(), 20);
641/// assert_eq!(tripled.get(), 30);
642/// ```
643///
644/// # Author
645///
646/// Haixing Hu
647pub struct ArcSupplier<T> {
648 function: Arc<dyn Fn() -> T + Send + Sync>,
649 name: Option<String>,
650}
651
652impl<T> ArcSupplier<T> {
653 // Generates: new(), new_with_name(), name(), set_name()
654 // Note: constant() is NOT generated here, implemented separately below
655 crate::macros::impl_common_new_methods!(
656 (Fn() -> T + Send + Sync + 'static),
657 |f| Arc::new(f),
658 "supplier"
659 );
660
661 crate::macros::impl_common_name_methods!("supplier");
662
663 // Generates: map(), filter(), zip()
664 impl_shared_supplier_methods!(ArcSupplier<T>, Supplier, (arc));
665}
666
667// Separate impl block for constant() with stricter T: Sync bound
668impl<T> ArcSupplier<T> {
669 /// Creates a supplier that returns a constant value.
670 ///
671 /// Creates a supplier that always returns the same value. Useful for
672 /// default values or placeholder implementations.
673 ///
674 /// **Note:** This method requires `T: Sync` because the constant value
675 /// is captured by a `Fn` closure which needs to be `Sync` for `Arc`.
676 ///
677 /// # Parameters
678 ///
679 /// * `value` - The constant value to return
680 ///
681 /// # Returns
682 ///
683 /// Returns a new supplier instance that returns the constant value.
684 ///
685 /// # Examples
686 ///
687 /// ```rust
688 /// use qubit_function::{ArcSupplier, Supplier};
689 ///
690 /// let supplier = ArcSupplier::constant(42);
691 /// assert_eq!(supplier.get(), 42);
692 /// assert_eq!(supplier.get(), 42); // Can be called multiple times
693 /// ```
694 pub fn constant(value: T) -> Self
695 where
696 T: Clone + Send + Sync + 'static,
697 {
698 Self::new(move || value.clone())
699 }
700}
701
702// Generates: Debug and Display implementations for ArcSupplier<T>
703impl_supplier_debug_display!(ArcSupplier<T>);
704
705// Generates: Clone implementation for ArcSupplier<T>
706impl_supplier_clone!(ArcSupplier<T>);
707
708impl<T> Supplier<T> for ArcSupplier<T> {
709 fn get(&self) -> T {
710 (self.function)()
711 }
712
713 // Use macro to implement conversion methods
714 impl_arc_conversions!(
715 ArcSupplier<T>,
716 BoxSupplier,
717 RcSupplier,
718 BoxSupplierOnce,
719 Fn() -> T
720 );
721}
722
723// ======================================================================
724// RcSupplier - Single-threaded Shared Ownership
725// ======================================================================
726
727/// Single-threaded shared ownership read-only supplier.
728///
729/// Uses `Rc<dyn Fn() -> T>` for single-threaded shared ownership.
730/// Can be cloned but not sent across threads.
731///
732/// # Ownership Model
733///
734/// Like `ArcSupplier`, methods borrow `&self` instead of
735/// consuming `self`:
736///
737/// ```rust
738/// use qubit_function::{RcSupplier, Supplier};
739///
740/// let source = RcSupplier::new(|| 10);
741/// let mapped = source.map(|x| x * 2);
742/// // source is still usable here!
743/// ```
744///
745/// # Examples
746///
747/// ## Shared Factory
748///
749/// ```rust
750/// use qubit_function::{RcSupplier, Supplier};
751///
752/// let factory = RcSupplier::new(|| {
753/// String::from("Hello")
754/// });
755///
756/// let f1 = factory.clone();
757/// let f2 = factory.clone();
758/// assert_eq!(f1.get(), "Hello");
759/// assert_eq!(f2.get(), "Hello");
760/// ```
761///
762/// ## Reusable Transformations
763///
764/// ```rust
765/// use qubit_function::{RcSupplier, Supplier};
766///
767/// let base = RcSupplier::new(|| 10);
768/// let doubled = base.map(|x| x * 2);
769/// let tripled = base.map(|x| x * 3);
770///
771/// assert_eq!(base.get(), 10);
772/// assert_eq!(doubled.get(), 20);
773/// assert_eq!(tripled.get(), 30);
774/// ```
775///
776/// # Author
777///
778/// Haixing Hu
779pub struct RcSupplier<T> {
780 function: Rc<dyn Fn() -> T>,
781 name: Option<String>,
782}
783
784impl<T> RcSupplier<T> {
785 // Generates: new(), new_with_name(), name(), set_name(), constant()
786 impl_supplier_common_methods!(RcSupplier<T>, (Fn() -> T + 'static), |f| Rc::new(f));
787
788 // Generates: map(), filter(), zip()
789 impl_shared_supplier_methods!(
790 RcSupplier<T>,
791 Supplier,
792 ('static)
793 );
794}
795
796// Generates: Debug and Display implementations for RcSupplier<T>
797impl_supplier_debug_display!(RcSupplier<T>);
798
799// Generates: Clone implementation for RcSupplier<T>
800impl_supplier_clone!(RcSupplier<T>);
801
802impl<T> Supplier<T> for RcSupplier<T> {
803 fn get(&self) -> T {
804 (self.function)()
805 }
806
807 // Generate all conversion methods using the unified macro
808 impl_rc_conversions!(
809 RcSupplier<T>,
810 BoxSupplier,
811 BoxSupplierOnce,
812 Fn() -> T
813 );
814}
815
816// ======================================================================
817// Implement Supplier for Closures
818// ======================================================================
819
820// Implement Supplier<T> for any type that implements Fn() -> T
821impl_closure_trait!(
822 Supplier<T>,
823 get,
824 BoxSupplierOnce,
825 Fn() -> T
826);
827
828// ======================================================================
829// Note on Extension Traits for Closures
830// ======================================================================
831//
832// We don't provide `FnSupplierOps` trait for `Fn() -> T` closures
833// because:
834//
835// 1. All `Fn` closures also implement `FnMut`, so they can use `FnSupplierOps`
836// from the `supplier` module
837// 2. Providing both would cause ambiguity errors due to overlapping trait impls
838// 3. Rust doesn't support negative trait bounds to exclude `FnMut`
839//
840// Users of `Fn` closures should use `FnSupplierOps` from `supplier` module,
841// or explicitly convert to `BoxSupplier` using `.into_box()` first.