1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//! # Constant Values for Reactive Computation
//!
//! This module provides functionality for working with constant reactive values.
//!
//! ## Overview
//!
//! Constants are immutable values that implement the `Signal` trait but never change.
//! They provide a way to incorporate fixed values into a reactive computation graph.
//!
//! ## Examples
//!
//! ```
//! use nami::{Signal, SignalExt, constant, binding, Binding};
//!
//! // Create a constant
//! let tax_rate = constant(0.08);
//!
//! // Use in a reactive computation
//! let price: Binding<f64> = binding(100.0);
//! let total = price.zip(&tax_rate)
//! .map(|(price, rate)| price * (1.0 + rate));
//!
//! assert_eq!(total.get(), 108.0);
//! ```
use RefCell;
use crate::;
/// A reactive constant value that never changes.
///
/// `Constant<T>` is a simple implementation of the `Signal` trait that always
/// returns the same value when computed. It serves as a way to introduce static
/// values into a reactive computation graph.
///
/// # Type Parameters
///
/// * `T`: The value type, which must be `Clone + 'static`.
///
/// # Examples
///
/// ```
/// use nami::{Signal, constant};
///
/// let c = constant(42);
/// assert_eq!(c.get(), 42);
/// ```
;
/// Creates a new constant reactive value.
///
/// This is a convenience function for creating a `Constant<T>` instance.
///
/// # Parameters
///
/// * `value`: The value to be wrapped in a `Constant`.
///
/// # Returns
///
/// A new `Constant` instance containing the provided value.
///
/// # Examples
///
/// ```
/// use nami::{Signal, constant};
///
/// let c = constant("Hello, world!");
/// assert_eq!(c.get(), "Hello, world!");
/// ```
/// A lazy-evaluated constant that computes its value on first access.
///
/// Unlike `Constant<T>`, this type allows for deferred computation of the constant value.
impl_signal_ops!;
impl_signal_ops!;