pub trait OpenQasm: crate::gates::Gate
{
fn open_qasm(&self, _bit_names: &[String], _bits: &[usize])
-> crate::error::Result<String>
{
Err(crate::error::Error::from(
crate::error::ExportError::NotImplemented("OpenQasm", String::from(self.description()))
))
}
fn conditional_open_qasm(&self, condition: &str, bit_names: &[String],
bits: &[usize]) -> crate::error::Result<String>
{
let uncond_qasm = self.open_qasm(bit_names, bits)?;
Ok(format!("if ({}) {}", condition, uncond_qasm))
}
}
#[cfg(test)]
mod tests
{
use super::OpenQasm;
#[test]
fn test_conditional_open_qasm()
{
let bit_names = [String::from("qb0"), String::from("qb1")];
let res = crate::gates::H::new().conditional_open_qasm("b == 0", &bit_names, &[1]);
assert_eq!(res, Ok(String::from("if (b == 0) h qb1")));
}
}