Trait roqoqo::AsVec[][src]

pub trait AsVec<T> {
    fn as_vec(&self, range: T) -> Option<Vec<Operation>>;
}
Expand description

Trait for returning Vectors based on Range structs usually used for Index<> trait and slice access.

Required because Circuit does not have a continuous internal vector representation of the values. Returns a Vec instead of slices.

Example

use roqoqo::{Circuit, AsVec};
use roqoqo::operations::{DefinitionFloat, Operation, RotateZ};
use qoqo_calculator::CalculatorFloat;

let mut circuit = Circuit::new();
let definition = DefinitionFloat::new(String::from("ro"), 1, false);
let rotatez0 = RotateZ::new(0, CalculatorFloat::from(0.0));
circuit.add_operation(definition.clone());
circuit.add_operation(rotatez0.clone());

let vec_ops = vec![
    Operation::from(definition.clone()),
    Operation::from(rotatez0.clone()),
];

assert_eq!(circuit.as_vec(0..1).clone(), Some(vec![vec_ops[0].clone()])); // Range
assert_eq!(circuit.as_vec(0..).clone(), Some(vec_ops.clone())); // RangeTo
assert_eq!(circuit.as_vec(..1).clone(), Some(vec![vec_ops[0].clone()])); // RangeFrom

Required methods

Returns slice of Circuit as Vec.

Arguments

  • range - The indices of the slice of the Circuit to be returned.

Returns

  • Option<Vec<Operation>> - A vector of the operations in the Circuit with the specified indices.

Implementors