pub struct QuantumDiffusionModel { /* private fields */ }Expand description
Quantum diffusion model
Implementations§
Source§impl QuantumDiffusionModel
impl QuantumDiffusionModel
Sourcepub fn new(
data_dim: usize,
num_qubits: usize,
num_timesteps: usize,
noise_schedule: NoiseSchedule,
) -> Result<Self>
pub fn new( data_dim: usize, num_qubits: usize, num_timesteps: usize, noise_schedule: NoiseSchedule, ) -> Result<Self>
Create a new quantum diffusion model
Examples found in repository?
examples/quantum_diffusion.rs (line 84)
48fn compare_noise_schedules() -> Result<()> {
49 let num_timesteps = 100;
50
51 let schedules = vec![
52 (
53 "Linear",
54 NoiseSchedule::Linear {
55 beta_start: 0.0001,
56 beta_end: 0.02,
57 },
58 ),
59 ("Cosine", NoiseSchedule::Cosine { s: 0.008 }),
60 (
61 "Quadratic",
62 NoiseSchedule::Quadratic {
63 beta_start: 0.0001,
64 beta_end: 0.02,
65 },
66 ),
67 (
68 "Sigmoid",
69 NoiseSchedule::Sigmoid {
70 beta_start: 0.0001,
71 beta_end: 0.02,
72 },
73 ),
74 ];
75
76 println!(" Noise levels at different timesteps:");
77 println!(" Time Linear Cosine Quadratic Sigmoid");
78
79 for t in (0..=100).step_by(20) {
80 let t_idx = (t * (num_timesteps - 1) / 100).min(num_timesteps - 1);
81 print!(" t={t:3}%: ");
82
83 for (_, schedule) in &schedules {
84 let model = QuantumDiffusionModel::new(2, 4, num_timesteps, *schedule)?;
85 print!("{:8.4} ", model.betas()[t_idx]);
86 }
87 println!();
88 }
89
90 Ok(())
91}
92
93/// Train a quantum diffusion model
94fn train_diffusion_model() -> Result<()> {
95 // Generate synthetic 2D data (two moons)
96 let num_samples = 200;
97 let data = generate_two_moons(num_samples);
98
99 println!(" Generated {num_samples} samples of 2D two-moons data");
100
101 // Create diffusion model
102 let mut model = QuantumDiffusionModel::new(
103 2, // data dimension
104 4, // num qubits
105 50, // timesteps
106 NoiseSchedule::Cosine { s: 0.008 },
107 )?;
108
109 println!(" Created quantum diffusion model:");
110 println!(" - Data dimension: 2");
111 println!(" - Qubits: 4");
112 println!(" - Timesteps: 50");
113 println!(" - Schedule: Cosine");
114
115 // Train model
116 let mut optimizer = Adam::new(0.001);
117 let epochs = 100;
118 let batch_size = 32;
119
120 println!("\n Training for {epochs} epochs...");
121 let losses = model.train(&data, &mut optimizer, epochs, batch_size)?;
122
123 // Print training statistics
124 println!("\n Training Statistics:");
125 println!(" - Initial loss: {:.4}", losses[0]);
126 println!(" - Final loss: {:.4}", losses.last().unwrap());
127 println!(
128 " - Improvement: {:.2}%",
129 (1.0 - losses.last().unwrap() / losses[0]) * 100.0
130 );
131
132 Ok(())
133}
134
135/// Generate samples from trained model
136fn generate_samples() -> Result<()> {
137 // Create a simple trained model
138 let model = QuantumDiffusionModel::new(
139 2, // data dimension
140 4, // num qubits
141 50, // timesteps
142 NoiseSchedule::Linear {
143 beta_start: 0.0001,
144 beta_end: 0.02,
145 },
146 )?;
147
148 // Generate samples
149 let num_samples = 10;
150 println!(" Generating {num_samples} samples...");
151
152 let samples = model.generate(num_samples)?;
153
154 println!("\n Generated samples:");
155 for i in 0..num_samples.min(5) {
156 println!(
157 " Sample {}: [{:.3}, {:.3}]",
158 i + 1,
159 samples[[i, 0]],
160 samples[[i, 1]]
161 );
162 }
163
164 // Compute statistics
165 let mean = samples.mean_axis(scirs2_core::ndarray::Axis(0)).unwrap();
166 let std = samples.std_axis(scirs2_core::ndarray::Axis(0), 0.0);
167
168 println!("\n Sample statistics:");
169 println!(" - Mean: [{:.3}, {:.3}]", mean[0], mean[1]);
170 println!(" - Std: [{:.3}, {:.3}]", std[0], std[1]);
171
172 Ok(())
173}
174
175/// Score-based diffusion demonstration
176fn score_diffusion_demo() -> Result<()> {
177 // Create score-based model
178 let model = QuantumScoreDiffusion::new(
179 2, // data dimension
180 4, // num qubits
181 10, // noise levels
182 )?;
183
184 println!(" Created quantum score-based diffusion model");
185 println!(" - Noise levels: {:?}", model.noise_levels());
186
187 // Test score estimation
188 let x = Array1::from_vec(vec![0.5, -0.3]);
189 let noise_level = 0.1;
190
191 let score = model.estimate_score(&x, noise_level)?;
192 println!("\n Score estimation:");
193 println!(" - Input: [{:.3}, {:.3}]", x[0], x[1]);
194 println!(" - Noise level: {noise_level:.3}");
195 println!(" - Estimated score: [{:.3}, {:.3}]", score[0], score[1]);
196
197 // Langevin sampling
198 println!("\n Langevin sampling:");
199 let init = Array1::from_vec(vec![2.0, 2.0]);
200 let num_steps = 100;
201 let step_size = 0.01;
202
203 let sample = model.langevin_sample(init.clone(), noise_level, num_steps, step_size)?;
204
205 println!(" - Initial: [{:.3}, {:.3}]", init[0], init[1]);
206 println!(
207 " - After {} steps: [{:.3}, {:.3}]",
208 num_steps, sample[0], sample[1]
209 );
210 println!(
211 " - Distance moved: {:.3}",
212 (sample[0] - init[0]).hypot(sample[1] - init[1])
213 );
214
215 Ok(())
216}
217
218/// Visualize the diffusion process
219fn visualize_diffusion_process() -> Result<()> {
220 let model = QuantumDiffusionModel::new(
221 2, // data dimension
222 4, // num qubits
223 20, // fewer timesteps for visualization
224 NoiseSchedule::Linear {
225 beta_start: 0.0001,
226 beta_end: 0.02,
227 },
228 )?;
229
230 // Start with a clear data point
231 let x0 = Array1::from_vec(vec![1.0, 0.5]);
232
233 println!(" Forward diffusion process:");
234 println!(" t=0 (original): [{:.3}, {:.3}]", x0[0], x0[1]);
235
236 // Show forward diffusion at different timesteps
237 for t in [5, 10, 15, 19] {
238 let (xt, _) = model.forward_diffusion(&x0, t)?;
239 let noise_level = (1.0 - model.alphas_cumprod()[t]).sqrt();
240 println!(
241 " t={:2} (noise={:.3}): [{:.3}, {:.3}]",
242 t, noise_level, xt[0], xt[1]
243 );
244 }
245
246 println!("\n Reverse diffusion process:");
247
248 // Start from noise
249 let mut xt = Array1::from_vec(vec![
250 2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0),
251 2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0),
252 ]);
253
254 println!(" t=19 (pure noise): [{:.3}, {:.3}]", xt[0], xt[1]);
255
256 // Show reverse diffusion
257 for t in [15, 10, 5, 0] {
258 xt = model.reverse_diffusion_step(&xt, t)?;
259 println!(" t={:2} (denoised): [{:.3}, {:.3}]", t, xt[0], xt[1]);
260 }
261
262 println!("\n This demonstrates how diffusion models:");
263 println!(" 1. Gradually add noise to data (forward process)");
264 println!(" 2. Learn to reverse this process (backward process)");
265 println!(" 3. Generate new samples by denoising random noise");
266
267 Ok(())
268}
269
270/// Generate two-moons dataset
271fn generate_two_moons(n_samples: usize) -> Array2<f64> {
272 let mut data = Array2::zeros((n_samples, 2));
273 let n_samples_per_moon = n_samples / 2;
274
275 // First moon
276 for i in 0..n_samples_per_moon {
277 let angle = std::f64::consts::PI * i as f64 / n_samples_per_moon as f64;
278 data[[i, 0]] = 0.1f64.mul_add(2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0), angle.cos());
279 data[[i, 1]] = 0.1f64.mul_add(2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0), angle.sin());
280 }
281
282 // Second moon (shifted and flipped)
283 for i in 0..n_samples_per_moon {
284 let idx = n_samples_per_moon + i;
285 let angle = std::f64::consts::PI * i as f64 / n_samples_per_moon as f64;
286 data[[idx, 0]] = 0.1f64.mul_add(
287 2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0),
288 1.0 - angle.cos(),
289 );
290 data[[idx, 1]] = 0.1f64.mul_add(
291 2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0),
292 0.5 - angle.sin(),
293 );
294 }
295
296 data
297}
298
299/// Advanced diffusion techniques demonstration
300fn advanced_diffusion_demo() -> Result<()> {
301 println!("\n6. Advanced Diffusion Techniques:");
302
303 // Conditional generation
304 println!("\n a) Conditional Generation:");
305 let model = QuantumDiffusionModel::new(4, 4, 50, NoiseSchedule::Cosine { s: 0.008 })?;
306 let condition = Array1::from_vec(vec![0.5, -0.5]);
307 let conditional_samples = model.conditional_generate(&condition, 5)?;
308
309 println!(
310 " Generated {} conditional samples",
311 conditional_samples.nrows()
312 );
313 println!(" Condition: [{:.3}, {:.3}]", condition[0], condition[1]);
314
315 // Variational diffusion
316 println!("\n b) Variational Diffusion Model:");
317 let vdm = QuantumVariationalDiffusion::new(
318 4, // data_dim
319 2, // latent_dim
320 4, // num_qubits
321 )?;
322
323 let x = Array1::from_vec(vec![0.1, 0.2, 0.3, 0.4]);
324 let (mean, log_var) = vdm.encode(&x)?;
325
326 println!(" Encoded data to latent space:");
327 println!(" - Input: {:?}", x.as_slice().unwrap());
328 println!(" - Latent mean: [{:.3}, {:.3}]", mean[0], mean[1]);
329 println!(
330 " - Latent log_var: [{:.3}, {:.3}]",
331 log_var[0], log_var[1]
332 );
333
334 Ok(())
335}Sourcepub fn forward_diffusion(
&self,
x0: &Array1<f64>,
t: usize,
) -> Result<(Array1<f64>, Array1<f64>)>
pub fn forward_diffusion( &self, x0: &Array1<f64>, t: usize, ) -> Result<(Array1<f64>, Array1<f64>)>
Forward diffusion process: add noise to data
Examples found in repository?
examples/quantum_diffusion.rs (line 238)
219fn visualize_diffusion_process() -> Result<()> {
220 let model = QuantumDiffusionModel::new(
221 2, // data dimension
222 4, // num qubits
223 20, // fewer timesteps for visualization
224 NoiseSchedule::Linear {
225 beta_start: 0.0001,
226 beta_end: 0.02,
227 },
228 )?;
229
230 // Start with a clear data point
231 let x0 = Array1::from_vec(vec![1.0, 0.5]);
232
233 println!(" Forward diffusion process:");
234 println!(" t=0 (original): [{:.3}, {:.3}]", x0[0], x0[1]);
235
236 // Show forward diffusion at different timesteps
237 for t in [5, 10, 15, 19] {
238 let (xt, _) = model.forward_diffusion(&x0, t)?;
239 let noise_level = (1.0 - model.alphas_cumprod()[t]).sqrt();
240 println!(
241 " t={:2} (noise={:.3}): [{:.3}, {:.3}]",
242 t, noise_level, xt[0], xt[1]
243 );
244 }
245
246 println!("\n Reverse diffusion process:");
247
248 // Start from noise
249 let mut xt = Array1::from_vec(vec![
250 2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0),
251 2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0),
252 ]);
253
254 println!(" t=19 (pure noise): [{:.3}, {:.3}]", xt[0], xt[1]);
255
256 // Show reverse diffusion
257 for t in [15, 10, 5, 0] {
258 xt = model.reverse_diffusion_step(&xt, t)?;
259 println!(" t={:2} (denoised): [{:.3}, {:.3}]", t, xt[0], xt[1]);
260 }
261
262 println!("\n This demonstrates how diffusion models:");
263 println!(" 1. Gradually add noise to data (forward process)");
264 println!(" 2. Learn to reverse this process (backward process)");
265 println!(" 3. Generate new samples by denoising random noise");
266
267 Ok(())
268}Sourcepub fn predict_noise(&self, xt: &Array1<f64>, t: usize) -> Result<Array1<f64>>
pub fn predict_noise(&self, xt: &Array1<f64>, t: usize) -> Result<Array1<f64>>
Predict noise from noisy data using quantum circuit
Sourcepub fn reverse_diffusion_step(
&self,
xt: &Array1<f64>,
t: usize,
) -> Result<Array1<f64>>
pub fn reverse_diffusion_step( &self, xt: &Array1<f64>, t: usize, ) -> Result<Array1<f64>>
Reverse diffusion process: denoise step by step
Examples found in repository?
examples/quantum_diffusion.rs (line 258)
219fn visualize_diffusion_process() -> Result<()> {
220 let model = QuantumDiffusionModel::new(
221 2, // data dimension
222 4, // num qubits
223 20, // fewer timesteps for visualization
224 NoiseSchedule::Linear {
225 beta_start: 0.0001,
226 beta_end: 0.02,
227 },
228 )?;
229
230 // Start with a clear data point
231 let x0 = Array1::from_vec(vec![1.0, 0.5]);
232
233 println!(" Forward diffusion process:");
234 println!(" t=0 (original): [{:.3}, {:.3}]", x0[0], x0[1]);
235
236 // Show forward diffusion at different timesteps
237 for t in [5, 10, 15, 19] {
238 let (xt, _) = model.forward_diffusion(&x0, t)?;
239 let noise_level = (1.0 - model.alphas_cumprod()[t]).sqrt();
240 println!(
241 " t={:2} (noise={:.3}): [{:.3}, {:.3}]",
242 t, noise_level, xt[0], xt[1]
243 );
244 }
245
246 println!("\n Reverse diffusion process:");
247
248 // Start from noise
249 let mut xt = Array1::from_vec(vec![
250 2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0),
251 2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0),
252 ]);
253
254 println!(" t=19 (pure noise): [{:.3}, {:.3}]", xt[0], xt[1]);
255
256 // Show reverse diffusion
257 for t in [15, 10, 5, 0] {
258 xt = model.reverse_diffusion_step(&xt, t)?;
259 println!(" t={:2} (denoised): [{:.3}, {:.3}]", t, xt[0], xt[1]);
260 }
261
262 println!("\n This demonstrates how diffusion models:");
263 println!(" 1. Gradually add noise to data (forward process)");
264 println!(" 2. Learn to reverse this process (backward process)");
265 println!(" 3. Generate new samples by denoising random noise");
266
267 Ok(())
268}Sourcepub fn generate(&self, num_samples: usize) -> Result<Array2<f64>>
pub fn generate(&self, num_samples: usize) -> Result<Array2<f64>>
Generate new samples
Examples found in repository?
examples/quantum_diffusion.rs (line 152)
136fn generate_samples() -> Result<()> {
137 // Create a simple trained model
138 let model = QuantumDiffusionModel::new(
139 2, // data dimension
140 4, // num qubits
141 50, // timesteps
142 NoiseSchedule::Linear {
143 beta_start: 0.0001,
144 beta_end: 0.02,
145 },
146 )?;
147
148 // Generate samples
149 let num_samples = 10;
150 println!(" Generating {num_samples} samples...");
151
152 let samples = model.generate(num_samples)?;
153
154 println!("\n Generated samples:");
155 for i in 0..num_samples.min(5) {
156 println!(
157 " Sample {}: [{:.3}, {:.3}]",
158 i + 1,
159 samples[[i, 0]],
160 samples[[i, 1]]
161 );
162 }
163
164 // Compute statistics
165 let mean = samples.mean_axis(scirs2_core::ndarray::Axis(0)).unwrap();
166 let std = samples.std_axis(scirs2_core::ndarray::Axis(0), 0.0);
167
168 println!("\n Sample statistics:");
169 println!(" - Mean: [{:.3}, {:.3}]", mean[0], mean[1]);
170 println!(" - Std: [{:.3}, {:.3}]", std[0], std[1]);
171
172 Ok(())
173}Sourcepub fn train(
&mut self,
data: &Array2<f64>,
optimizer: &mut dyn Optimizer,
epochs: usize,
batch_size: usize,
) -> Result<Vec<f64>>
pub fn train( &mut self, data: &Array2<f64>, optimizer: &mut dyn Optimizer, epochs: usize, batch_size: usize, ) -> Result<Vec<f64>>
Train the diffusion model
Examples found in repository?
examples/quantum_diffusion.rs (line 121)
94fn train_diffusion_model() -> Result<()> {
95 // Generate synthetic 2D data (two moons)
96 let num_samples = 200;
97 let data = generate_two_moons(num_samples);
98
99 println!(" Generated {num_samples} samples of 2D two-moons data");
100
101 // Create diffusion model
102 let mut model = QuantumDiffusionModel::new(
103 2, // data dimension
104 4, // num qubits
105 50, // timesteps
106 NoiseSchedule::Cosine { s: 0.008 },
107 )?;
108
109 println!(" Created quantum diffusion model:");
110 println!(" - Data dimension: 2");
111 println!(" - Qubits: 4");
112 println!(" - Timesteps: 50");
113 println!(" - Schedule: Cosine");
114
115 // Train model
116 let mut optimizer = Adam::new(0.001);
117 let epochs = 100;
118 let batch_size = 32;
119
120 println!("\n Training for {epochs} epochs...");
121 let losses = model.train(&data, &mut optimizer, epochs, batch_size)?;
122
123 // Print training statistics
124 println!("\n Training Statistics:");
125 println!(" - Initial loss: {:.4}", losses[0]);
126 println!(" - Final loss: {:.4}", losses.last().unwrap());
127 println!(
128 " - Improvement: {:.2}%",
129 (1.0 - losses.last().unwrap() / losses[0]) * 100.0
130 );
131
132 Ok(())
133}Sourcepub fn conditional_generate(
&self,
condition: &Array1<f64>,
num_samples: usize,
) -> Result<Array2<f64>>
pub fn conditional_generate( &self, condition: &Array1<f64>, num_samples: usize, ) -> Result<Array2<f64>>
Conditional generation given a condition
Examples found in repository?
examples/quantum_diffusion.rs (line 307)
300fn advanced_diffusion_demo() -> Result<()> {
301 println!("\n6. Advanced Diffusion Techniques:");
302
303 // Conditional generation
304 println!("\n a) Conditional Generation:");
305 let model = QuantumDiffusionModel::new(4, 4, 50, NoiseSchedule::Cosine { s: 0.008 })?;
306 let condition = Array1::from_vec(vec![0.5, -0.5]);
307 let conditional_samples = model.conditional_generate(&condition, 5)?;
308
309 println!(
310 " Generated {} conditional samples",
311 conditional_samples.nrows()
312 );
313 println!(" Condition: [{:.3}, {:.3}]", condition[0], condition[1]);
314
315 // Variational diffusion
316 println!("\n b) Variational Diffusion Model:");
317 let vdm = QuantumVariationalDiffusion::new(
318 4, // data_dim
319 2, // latent_dim
320 4, // num_qubits
321 )?;
322
323 let x = Array1::from_vec(vec![0.1, 0.2, 0.3, 0.4]);
324 let (mean, log_var) = vdm.encode(&x)?;
325
326 println!(" Encoded data to latent space:");
327 println!(" - Input: {:?}", x.as_slice().unwrap());
328 println!(" - Latent mean: [{:.3}, {:.3}]", mean[0], mean[1]);
329 println!(
330 " - Latent log_var: [{:.3}, {:.3}]",
331 log_var[0], log_var[1]
332 );
333
334 Ok(())
335}Sourcepub fn betas(&self) -> &Array1<f64>
pub fn betas(&self) -> &Array1<f64>
Get beta values
Examples found in repository?
examples/quantum_diffusion.rs (line 85)
48fn compare_noise_schedules() -> Result<()> {
49 let num_timesteps = 100;
50
51 let schedules = vec![
52 (
53 "Linear",
54 NoiseSchedule::Linear {
55 beta_start: 0.0001,
56 beta_end: 0.02,
57 },
58 ),
59 ("Cosine", NoiseSchedule::Cosine { s: 0.008 }),
60 (
61 "Quadratic",
62 NoiseSchedule::Quadratic {
63 beta_start: 0.0001,
64 beta_end: 0.02,
65 },
66 ),
67 (
68 "Sigmoid",
69 NoiseSchedule::Sigmoid {
70 beta_start: 0.0001,
71 beta_end: 0.02,
72 },
73 ),
74 ];
75
76 println!(" Noise levels at different timesteps:");
77 println!(" Time Linear Cosine Quadratic Sigmoid");
78
79 for t in (0..=100).step_by(20) {
80 let t_idx = (t * (num_timesteps - 1) / 100).min(num_timesteps - 1);
81 print!(" t={t:3}%: ");
82
83 for (_, schedule) in &schedules {
84 let model = QuantumDiffusionModel::new(2, 4, num_timesteps, *schedule)?;
85 print!("{:8.4} ", model.betas()[t_idx]);
86 }
87 println!();
88 }
89
90 Ok(())
91}Sourcepub fn alphas_cumprod(&self) -> &Array1<f64>
pub fn alphas_cumprod(&self) -> &Array1<f64>
Get alpha cumulative product values
Examples found in repository?
examples/quantum_diffusion.rs (line 239)
219fn visualize_diffusion_process() -> Result<()> {
220 let model = QuantumDiffusionModel::new(
221 2, // data dimension
222 4, // num qubits
223 20, // fewer timesteps for visualization
224 NoiseSchedule::Linear {
225 beta_start: 0.0001,
226 beta_end: 0.02,
227 },
228 )?;
229
230 // Start with a clear data point
231 let x0 = Array1::from_vec(vec![1.0, 0.5]);
232
233 println!(" Forward diffusion process:");
234 println!(" t=0 (original): [{:.3}, {:.3}]", x0[0], x0[1]);
235
236 // Show forward diffusion at different timesteps
237 for t in [5, 10, 15, 19] {
238 let (xt, _) = model.forward_diffusion(&x0, t)?;
239 let noise_level = (1.0 - model.alphas_cumprod()[t]).sqrt();
240 println!(
241 " t={:2} (noise={:.3}): [{:.3}, {:.3}]",
242 t, noise_level, xt[0], xt[1]
243 );
244 }
245
246 println!("\n Reverse diffusion process:");
247
248 // Start from noise
249 let mut xt = Array1::from_vec(vec![
250 2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0),
251 2.0f64.mul_add(thread_rng().gen::<f64>(), -1.0),
252 ]);
253
254 println!(" t=19 (pure noise): [{:.3}, {:.3}]", xt[0], xt[1]);
255
256 // Show reverse diffusion
257 for t in [15, 10, 5, 0] {
258 xt = model.reverse_diffusion_step(&xt, t)?;
259 println!(" t={:2} (denoised): [{:.3}, {:.3}]", t, xt[0], xt[1]);
260 }
261
262 println!("\n This demonstrates how diffusion models:");
263 println!(" 1. Gradually add noise to data (forward process)");
264 println!(" 2. Learn to reverse this process (backward process)");
265 println!(" 3. Generate new samples by denoising random noise");
266
267 Ok(())
268}Auto Trait Implementations§
impl Freeze for QuantumDiffusionModel
impl RefUnwindSafe for QuantumDiffusionModel
impl Send for QuantumDiffusionModel
impl Sync for QuantumDiffusionModel
impl Unpin for QuantumDiffusionModel
impl UnwindSafe for QuantumDiffusionModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.