BoxConditionalMutatorOnce

Struct BoxConditionalMutatorOnce 

Source
pub struct BoxConditionalMutatorOnce<T> { /* private fields */ }
Expand description

BoxConditionalMutatorOnce struct

A conditional one-time mutator that only executes when a predicate is satisfied. Uses BoxMutatorOnce and BoxPredicate for single ownership semantics.

This type is typically created by calling BoxMutatorOnce::when() and is designed to work with the or_else() method to create if-then-else logic.

§Features

  • Single Ownership: Not cloneable, consumes self on use
  • Conditional Execution: Only mutates when predicate returns true
  • Chainable: Can add or_else branch to create if-then-else logic
  • Implements MutatorOnce: Can be used anywhere a MutatorOnce is expected

§Examples

§Basic Conditional Execution

use prism3_function::{MutatorOnce, BoxMutatorOnce};

let data = vec![1, 2, 3];
let mutator = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
    x.extend(data);
});
let conditional = mutator.when(|x: &Vec<i32>| !x.is_empty());

let mut target = vec![0];
conditional.mutate_once(&mut target);
assert_eq!(target, vec![0, 1, 2, 3]); // Executed

let mut empty = Vec::new();
let data2 = vec![4, 5];
let mutator2 = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
    x.extend(data2);
});
let conditional2 = mutator2.when(|x: &Vec<i32>| x.len() > 5);
conditional2.mutate_once(&mut empty);
assert_eq!(empty, Vec::<i32>::new()); // Not executed

§With or_else Branch

use prism3_function::{MutatorOnce, BoxMutatorOnce};

let data1 = vec![1, 2, 3];
let data2 = vec![99];
let mutator = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
    x.extend(data1);
})
.when(|x: &Vec<i32>| !x.is_empty())
.or_else(move |x: &mut Vec<i32>| {
    x.extend(data2);
});

let mut target = vec![0];
mutator.mutate_once(&mut target);
assert_eq!(target, vec![0, 1, 2, 3]); // when branch executed

let data3 = vec![4, 5];
let data4 = vec![99];
let mutator2 = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
    x.extend(data3);
})
.when(|x: &Vec<i32>| x.is_empty())
.or_else(move |x: &mut Vec<i32>| {
    x.extend(data4);
});

let mut target2 = vec![0];
mutator2.mutate_once(&mut target2);
assert_eq!(target2, vec![0, 99]); // or_else branch executed

§Author

Haixing Hu

Implementations§

Source§

impl<T> BoxConditionalMutatorOnce<T>
where T: 'static,

Source

pub fn and_then<C>(self, next: C) -> BoxMutatorOnce<T>
where C: MutatorOnce<T> + 'static,

Chains another mutator in sequence

Combines the current conditional mutator with another mutator into a new mutator. The current conditional mutator executes first, followed by the next mutator.

§Parameters
  • next - The next mutator to execute. Note: This parameter is passed by value and will transfer ownership. Since BoxMutatorOnce cannot be cloned, the parameter will be consumed. Can be:
    • A closure: |x: &mut T|
    • A BoxMutatorOnce<T>
    • Any type implementing MutatorOnce<T>
§Returns

Returns a new BoxMutatorOnce<T>

§Examples
use prism3_function::{MutatorOnce, BoxMutatorOnce};

let data1 = vec![1, 2];
let cond1 = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
    x.extend(data1);
}).when(|x: &Vec<i32>| !x.is_empty());

let data2 = vec![3, 4];
let cond2 = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
    x.extend(data2);
}).when(|x: &Vec<i32>| x.len() < 10);

// Both cond1 and cond2 are moved and consumed
let chained = cond1.and_then(cond2);

let mut target = vec![0];
chained.mutate_once(&mut target);
assert_eq!(target, vec![0, 1, 2, 3, 4]);
// cond1.mutate_once(&mut target); // Would not compile - moved
// cond2.mutate_once(&mut target); // Would not compile - moved
Examples found in repository?
examples/mutator_once_conditional_demo.rs (line 191)
16fn main() {
17    println!("=== MutatorOnce Conditional Execution Examples ===\n");
18
19    // 1. Basic conditional execution - when condition is satisfied
20    println!("1. Basic conditional execution - when condition is satisfied");
21    let data = vec![1, 2, 3];
22    let mutator = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
23        println!("   Extending vector with data: {:?}", data);
24        x.extend(data);
25    });
26    let conditional = mutator.when(|x: &Vec<i32>| {
27        println!("   Checking condition: !x.is_empty()");
28        !x.is_empty()
29    });
30
31    let mut target = vec![0];
32    println!("   Initial: {:?}", target);
33    conditional.mutate_once(&mut target);
34    println!("   Result: {:?}\n", target);
35
36    // 2. Conditional execution - when condition is not satisfied
37    println!("2. Conditional execution - when condition is not satisfied");
38    let data = vec![4, 5, 6];
39    let mutator = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
40        println!("   This should not be executed");
41        x.extend(data);
42    });
43    let conditional = mutator.when(|x: &Vec<i32>| {
44        println!("   Checking condition: x.len() > 10");
45        x.len() > 10
46    });
47
48    let mut target = vec![0];
49    println!("   Initial: {:?}", target);
50    conditional.mutate_once(&mut target);
51    println!("   Result: {:?} (unchanged)\n", target);
52
53    // 3. Using BoxPredicate
54    println!("3. Using BoxPredicate");
55    let pred = BoxPredicate::new(|x: &Vec<i32>| {
56        println!("   Predicate: checking if vector is not empty");
57        !x.is_empty()
58    });
59    let data = vec![7, 8, 9];
60    let mutator = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
61        println!("   Adding data: {:?}", data);
62        x.extend(data);
63    });
64    let conditional = mutator.when(pred);
65
66    let mut target = vec![0];
67    println!("   Initial: {:?}", target);
68    conditional.mutate_once(&mut target);
69    println!("   Result: {:?}\n", target);
70
71    // 4. Using composed predicate
72    println!("4. Using composed predicate");
73    let pred = (|x: &Vec<i32>| {
74        println!("   Condition 1: !x.is_empty()");
75        !x.is_empty()
76    })
77    .and(|x: &Vec<i32>| {
78        println!("   Condition 2: x.len() < 10");
79        x.len() < 10
80    });
81    let data = vec![10, 11, 12];
82    let mutator = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
83        println!("   Adding data: {:?}", data);
84        x.extend(data);
85    });
86    let conditional = mutator.when(pred);
87
88    let mut target = vec![0];
89    println!("   Initial: {:?}", target);
90    conditional.mutate_once(&mut target);
91    println!("   Result: {:?}\n", target);
92
93    // 5. If-then-else with or_else - when branch
94    println!("5. If-then-else with or_else - when branch");
95    let data1 = vec![1, 2, 3];
96    let data2 = vec![99];
97    let mutator = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
98        println!("   When branch: adding {:?}", data1);
99        x.extend(data1);
100    })
101    .when(|x: &Vec<i32>| {
102        println!("   Checking: !x.is_empty()");
103        !x.is_empty()
104    })
105    .or_else(move |x: &mut Vec<i32>| {
106        println!("   Else branch: adding {:?}", data2);
107        x.extend(data2);
108    });
109
110    let mut target = vec![0];
111    println!("   Initial: {:?}", target);
112    mutator.mutate_once(&mut target);
113    println!("   Result: {:?}\n", target);
114
115    // 6. If-then-else with or_else - else branch
116    println!("6. If-then-else with or_else - else branch");
117    let data1 = vec![4, 5, 6];
118    let data2 = vec![99];
119    let mutator = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
120        println!("   When branch: adding {:?}", data1);
121        x.extend(data1);
122    })
123    .when(|x: &Vec<i32>| {
124        println!("   Checking: x.is_empty()");
125        x.is_empty()
126    })
127    .or_else(move |x: &mut Vec<i32>| {
128        println!("   Else branch: adding {:?}", data2);
129        x.extend(data2);
130    });
131
132    let mut target = vec![0];
133    println!("   Initial: {:?}", target);
134    mutator.mutate_once(&mut target);
135    println!("   Result: {:?}\n", target);
136
137    // 7. Conditional with integers
138    println!("7. Conditional with integers");
139    let mutator = BoxMutatorOnce::new(|x: &mut i32| {
140        println!("   Multiplying by 2");
141        *x *= 2;
142    })
143    .when(|x: &i32| {
144        println!("   Checking: *x > 0");
145        *x > 0
146    });
147
148    let mut positive = 5;
149    println!("   Initial (positive): {}", positive);
150    mutator.mutate_once(&mut positive);
151    println!("   Result: {}\n", positive);
152
153    // 8. Conditional with integers - not executed
154    println!("8. Conditional with integers - not executed");
155    let mutator = BoxMutatorOnce::new(|x: &mut i32| {
156        println!("   This should not be executed");
157        *x *= 2;
158    })
159    .when(|x: &i32| {
160        println!("   Checking: *x > 0");
161        *x > 0
162    });
163
164    let mut negative = -5;
165    println!("   Initial (negative): {}", negative);
166    mutator.mutate_once(&mut negative);
167    println!("   Result: {} (unchanged)\n", negative);
168
169    // 9. Chaining conditional mutators
170    println!("9. Chaining conditional mutators");
171    let data1 = vec![1, 2];
172    let cond1 = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
173        println!("   First mutator: adding {:?}", data1);
174        x.extend(data1);
175    })
176    .when(|x: &Vec<i32>| {
177        println!("   First condition: !x.is_empty()");
178        !x.is_empty()
179    });
180
181    let data2 = vec![3, 4];
182    let cond2 = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
183        println!("   Second mutator: adding {:?}", data2);
184        x.extend(data2);
185    })
186    .when(|x: &Vec<i32>| {
187        println!("   Second condition: x.len() < 10");
188        x.len() < 10
189    });
190
191    let chained = cond1.and_then(cond2);
192
193    let mut target = vec![0];
194    println!("   Initial: {:?}", target);
195    chained.mutate_once(&mut target);
196    println!("   Result: {:?}\n", target);
197
198    // 10. Complex conditional chain
199    println!("10. Complex conditional chain");
200    let data1 = vec![1, 2];
201    let data2 = vec![99];
202    let data3 = vec![5, 6];
203
204    let mutator = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
205        println!("   When branch: adding {:?}", data1);
206        x.extend(data1);
207    })
208    .when(|x: &Vec<i32>| {
209        println!("   Checking: !x.is_empty()");
210        !x.is_empty()
211    })
212    .or_else(move |x: &mut Vec<i32>| {
213        println!("   Else branch: adding {:?}", data2);
214        x.extend(data2);
215    })
216    .and_then(move |x: &mut Vec<i32>| {
217        println!("   Final step: adding {:?}", data3);
218        x.extend(data3);
219    });
220
221    let mut target = vec![0];
222    println!("   Initial: {:?}", target);
223    mutator.mutate_once(&mut target);
224    println!("   Result: {:?}\n", target);
225
226    // 11. Real-world scenario: data validation and processing
227    println!("11. Real-world scenario: data validation and processing");
228
229    struct DataProcessor {
230        on_valid: Option<BoxMutatorOnce<Vec<String>>>,
231        on_invalid: Option<BoxMutatorOnce<Vec<String>>>,
232    }
233
234    impl DataProcessor {
235        fn new<V, I>(on_valid: V, on_invalid: I) -> Self
236        where
237            V: FnOnce(&mut Vec<String>) + 'static,
238            I: FnOnce(&mut Vec<String>) + 'static,
239        {
240            Self {
241                on_valid: Some(BoxMutatorOnce::new(on_valid)),
242                on_invalid: Some(BoxMutatorOnce::new(on_invalid)),
243            }
244        }
245
246        fn process(mut self, data: &mut Vec<String>) {
247            let is_valid = !data.is_empty() && data.iter().all(|s| !s.is_empty());
248            println!(
249                "   Data validation: {}",
250                if is_valid { "VALID" } else { "INVALID" }
251            );
252
253            if is_valid {
254                if let Some(callback) = self.on_valid.take() {
255                    callback.mutate_once(data);
256                }
257            } else if let Some(callback) = self.on_invalid.take() {
258                callback.mutate_once(data);
259            }
260        }
261    }
262
263    let valid_suffix = vec!["processed".to_string()];
264    let invalid_marker = vec!["[INVALID]".to_string()];
265
266    let processor = DataProcessor::new(
267        move |data| {
268            println!("   Valid data callback: adding suffix");
269            data.extend(valid_suffix);
270        },
271        move |data| {
272            println!("   Invalid data callback: adding error marker");
273            data.clear();
274            data.extend(invalid_marker);
275        },
276    );
277
278    let mut valid_data = vec!["item1".to_string(), "item2".to_string()];
279    println!("   Processing valid data: {:?}", valid_data);
280    processor.process(&mut valid_data);
281    println!("   Result: {:?}\n", valid_data);
282
283    println!("=== Examples completed ===");
284}
Source

pub fn or_else<C>(self, else_mutator: C) -> BoxMutatorOnce<T>
where C: MutatorOnce<T> + 'static,

Adds an else branch

Executes the original mutator when the condition is satisfied, otherwise executes else_mutator.

§Parameters
  • else_mutator - The mutator for the else branch. Note: This parameter is passed by value and will transfer ownership. Since BoxMutatorOnce cannot be cloned, the parameter will be consumed. Can be:
    • A closure: |x: &mut T|
    • A BoxMutatorOnce<T>
    • Any type implementing MutatorOnce<T>
§Returns

Returns the composed BoxMutatorOnce<T>

§Examples
use prism3_function::{MutatorOnce, BoxMutatorOnce};

let data1 = vec![1, 2, 3];
let data2 = vec![99];
let mutator = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
    x.extend(data1);
})
.when(|x: &Vec<i32>| !x.is_empty())
.or_else(move |x: &mut Vec<i32>| {
    x.extend(data2);
});

let mut target = vec![0];
mutator.mutate_once(&mut target);
assert_eq!(target, vec![0, 1, 2, 3]); // Condition satisfied, execute when branch

let data3 = vec![4, 5];
let data4 = vec![99];
let mutator2 = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
    x.extend(data3);
})
.when(|x: &Vec<i32>| x.is_empty())
.or_else(move |x: &mut Vec<i32>| {
    x.extend(data4);
});

let mut target2 = vec![0];
mutator2.mutate_once(&mut target2);
assert_eq!(target2, vec![0, 99]); // Condition not satisfied, execute or_else branch
Examples found in repository?
examples/mutator_once_conditional_demo.rs (lines 105-108)
16fn main() {
17    println!("=== MutatorOnce Conditional Execution Examples ===\n");
18
19    // 1. Basic conditional execution - when condition is satisfied
20    println!("1. Basic conditional execution - when condition is satisfied");
21    let data = vec![1, 2, 3];
22    let mutator = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
23        println!("   Extending vector with data: {:?}", data);
24        x.extend(data);
25    });
26    let conditional = mutator.when(|x: &Vec<i32>| {
27        println!("   Checking condition: !x.is_empty()");
28        !x.is_empty()
29    });
30
31    let mut target = vec![0];
32    println!("   Initial: {:?}", target);
33    conditional.mutate_once(&mut target);
34    println!("   Result: {:?}\n", target);
35
36    // 2. Conditional execution - when condition is not satisfied
37    println!("2. Conditional execution - when condition is not satisfied");
38    let data = vec![4, 5, 6];
39    let mutator = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
40        println!("   This should not be executed");
41        x.extend(data);
42    });
43    let conditional = mutator.when(|x: &Vec<i32>| {
44        println!("   Checking condition: x.len() > 10");
45        x.len() > 10
46    });
47
48    let mut target = vec![0];
49    println!("   Initial: {:?}", target);
50    conditional.mutate_once(&mut target);
51    println!("   Result: {:?} (unchanged)\n", target);
52
53    // 3. Using BoxPredicate
54    println!("3. Using BoxPredicate");
55    let pred = BoxPredicate::new(|x: &Vec<i32>| {
56        println!("   Predicate: checking if vector is not empty");
57        !x.is_empty()
58    });
59    let data = vec![7, 8, 9];
60    let mutator = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
61        println!("   Adding data: {:?}", data);
62        x.extend(data);
63    });
64    let conditional = mutator.when(pred);
65
66    let mut target = vec![0];
67    println!("   Initial: {:?}", target);
68    conditional.mutate_once(&mut target);
69    println!("   Result: {:?}\n", target);
70
71    // 4. Using composed predicate
72    println!("4. Using composed predicate");
73    let pred = (|x: &Vec<i32>| {
74        println!("   Condition 1: !x.is_empty()");
75        !x.is_empty()
76    })
77    .and(|x: &Vec<i32>| {
78        println!("   Condition 2: x.len() < 10");
79        x.len() < 10
80    });
81    let data = vec![10, 11, 12];
82    let mutator = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
83        println!("   Adding data: {:?}", data);
84        x.extend(data);
85    });
86    let conditional = mutator.when(pred);
87
88    let mut target = vec![0];
89    println!("   Initial: {:?}", target);
90    conditional.mutate_once(&mut target);
91    println!("   Result: {:?}\n", target);
92
93    // 5. If-then-else with or_else - when branch
94    println!("5. If-then-else with or_else - when branch");
95    let data1 = vec![1, 2, 3];
96    let data2 = vec![99];
97    let mutator = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
98        println!("   When branch: adding {:?}", data1);
99        x.extend(data1);
100    })
101    .when(|x: &Vec<i32>| {
102        println!("   Checking: !x.is_empty()");
103        !x.is_empty()
104    })
105    .or_else(move |x: &mut Vec<i32>| {
106        println!("   Else branch: adding {:?}", data2);
107        x.extend(data2);
108    });
109
110    let mut target = vec![0];
111    println!("   Initial: {:?}", target);
112    mutator.mutate_once(&mut target);
113    println!("   Result: {:?}\n", target);
114
115    // 6. If-then-else with or_else - else branch
116    println!("6. If-then-else with or_else - else branch");
117    let data1 = vec![4, 5, 6];
118    let data2 = vec![99];
119    let mutator = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
120        println!("   When branch: adding {:?}", data1);
121        x.extend(data1);
122    })
123    .when(|x: &Vec<i32>| {
124        println!("   Checking: x.is_empty()");
125        x.is_empty()
126    })
127    .or_else(move |x: &mut Vec<i32>| {
128        println!("   Else branch: adding {:?}", data2);
129        x.extend(data2);
130    });
131
132    let mut target = vec![0];
133    println!("   Initial: {:?}", target);
134    mutator.mutate_once(&mut target);
135    println!("   Result: {:?}\n", target);
136
137    // 7. Conditional with integers
138    println!("7. Conditional with integers");
139    let mutator = BoxMutatorOnce::new(|x: &mut i32| {
140        println!("   Multiplying by 2");
141        *x *= 2;
142    })
143    .when(|x: &i32| {
144        println!("   Checking: *x > 0");
145        *x > 0
146    });
147
148    let mut positive = 5;
149    println!("   Initial (positive): {}", positive);
150    mutator.mutate_once(&mut positive);
151    println!("   Result: {}\n", positive);
152
153    // 8. Conditional with integers - not executed
154    println!("8. Conditional with integers - not executed");
155    let mutator = BoxMutatorOnce::new(|x: &mut i32| {
156        println!("   This should not be executed");
157        *x *= 2;
158    })
159    .when(|x: &i32| {
160        println!("   Checking: *x > 0");
161        *x > 0
162    });
163
164    let mut negative = -5;
165    println!("   Initial (negative): {}", negative);
166    mutator.mutate_once(&mut negative);
167    println!("   Result: {} (unchanged)\n", negative);
168
169    // 9. Chaining conditional mutators
170    println!("9. Chaining conditional mutators");
171    let data1 = vec![1, 2];
172    let cond1 = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
173        println!("   First mutator: adding {:?}", data1);
174        x.extend(data1);
175    })
176    .when(|x: &Vec<i32>| {
177        println!("   First condition: !x.is_empty()");
178        !x.is_empty()
179    });
180
181    let data2 = vec![3, 4];
182    let cond2 = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
183        println!("   Second mutator: adding {:?}", data2);
184        x.extend(data2);
185    })
186    .when(|x: &Vec<i32>| {
187        println!("   Second condition: x.len() < 10");
188        x.len() < 10
189    });
190
191    let chained = cond1.and_then(cond2);
192
193    let mut target = vec![0];
194    println!("   Initial: {:?}", target);
195    chained.mutate_once(&mut target);
196    println!("   Result: {:?}\n", target);
197
198    // 10. Complex conditional chain
199    println!("10. Complex conditional chain");
200    let data1 = vec![1, 2];
201    let data2 = vec![99];
202    let data3 = vec![5, 6];
203
204    let mutator = BoxMutatorOnce::new(move |x: &mut Vec<i32>| {
205        println!("   When branch: adding {:?}", data1);
206        x.extend(data1);
207    })
208    .when(|x: &Vec<i32>| {
209        println!("   Checking: !x.is_empty()");
210        !x.is_empty()
211    })
212    .or_else(move |x: &mut Vec<i32>| {
213        println!("   Else branch: adding {:?}", data2);
214        x.extend(data2);
215    })
216    .and_then(move |x: &mut Vec<i32>| {
217        println!("   Final step: adding {:?}", data3);
218        x.extend(data3);
219    });
220
221    let mut target = vec![0];
222    println!("   Initial: {:?}", target);
223    mutator.mutate_once(&mut target);
224    println!("   Result: {:?}\n", target);
225
226    // 11. Real-world scenario: data validation and processing
227    println!("11. Real-world scenario: data validation and processing");
228
229    struct DataProcessor {
230        on_valid: Option<BoxMutatorOnce<Vec<String>>>,
231        on_invalid: Option<BoxMutatorOnce<Vec<String>>>,
232    }
233
234    impl DataProcessor {
235        fn new<V, I>(on_valid: V, on_invalid: I) -> Self
236        where
237            V: FnOnce(&mut Vec<String>) + 'static,
238            I: FnOnce(&mut Vec<String>) + 'static,
239        {
240            Self {
241                on_valid: Some(BoxMutatorOnce::new(on_valid)),
242                on_invalid: Some(BoxMutatorOnce::new(on_invalid)),
243            }
244        }
245
246        fn process(mut self, data: &mut Vec<String>) {
247            let is_valid = !data.is_empty() && data.iter().all(|s| !s.is_empty());
248            println!(
249                "   Data validation: {}",
250                if is_valid { "VALID" } else { "INVALID" }
251            );
252
253            if is_valid {
254                if let Some(callback) = self.on_valid.take() {
255                    callback.mutate_once(data);
256                }
257            } else if let Some(callback) = self.on_invalid.take() {
258                callback.mutate_once(data);
259            }
260        }
261    }
262
263    let valid_suffix = vec!["processed".to_string()];
264    let invalid_marker = vec!["[INVALID]".to_string()];
265
266    let processor = DataProcessor::new(
267        move |data| {
268            println!("   Valid data callback: adding suffix");
269            data.extend(valid_suffix);
270        },
271        move |data| {
272            println!("   Invalid data callback: adding error marker");
273            data.clear();
274            data.extend(invalid_marker);
275        },
276    );
277
278    let mut valid_data = vec!["item1".to_string(), "item2".to_string()];
279    println!("   Processing valid data: {:?}", valid_data);
280    processor.process(&mut valid_data);
281    println!("   Result: {:?}\n", valid_data);
282
283    println!("=== Examples completed ===");
284}

Trait Implementations§

Source§

impl<T> MutatorOnce<T> for BoxConditionalMutatorOnce<T>
where T: 'static,

Source§

fn mutate_once(self, value: &mut T)

Performs the one-time mutation operation Read more
Source§

fn into_box_once(self) -> BoxMutatorOnce<T>

Converts to BoxMutatorOnce (consuming) Read more
Source§

fn into_fn_once(self) -> impl FnOnce(&mut T)

Converts to a consuming closure FnOnce(&mut T) Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.