Skip to main content

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 qubit_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.apply(&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.apply(&mut empty);
assert_eq!(empty, Vec::<i32>::new()); // Not executed

§With or_else Branch

use qubit_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.apply(&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.apply(&mut target2);
assert_eq!(target2, vec![0, 99]); // or_else branch executed

Implementations§

Source§

impl<T> BoxConditionalMutatorOnce<T>

Source

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

Chains another mutator in sequence

Combines the current conditional mutator with another mutator into a new mutator that implements the following semantics:

When the returned mutator is called with an argument:

  1. First, it checks the predicate of this conditional mutator
  2. If the predicate is satisfied, it executes the internal mutator of this conditional mutator
  3. Then, regardless of whether the predicate was satisfied, it unconditionally executes the next mutator

In other words, this creates a mutator that conditionally executes the first action (based on the predicate), and then always executes the second action.

§Parameters
  • next - The next mutator to execute (always executed)
§Returns

Returns a new combined mutator

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

pub fn or_else<M>(self, else_mutator: M) -> BoxMutatorOnce<T>
where T: 'static, M: 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
§Returns

Returns a new mutator with if-then-else logic

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

Trait Implementations§

Source§

impl<T> Debug for BoxConditionalMutatorOnce<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Display for BoxConditionalMutatorOnce<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> MutatorOnce<T> for BoxConditionalMutatorOnce<T>

Source§

fn apply(self, value: &mut T)

Performs the one-time mutation operation Read more
Source§

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

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

fn into_box(self) -> BoxMutatorOnce<T>
where Self: Sized + 'static,

Converts to BoxMutatorOnce (consuming) 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.