quil_rs/instruction/
reset.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use crate::quil::Quil;

use super::Qubit;

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Reset {
    pub qubit: Option<Qubit>,
}

impl Reset {
    pub fn new(qubit: Option<Qubit>) -> Self {
        Self { qubit }
    }
}

impl Quil for Reset {
    fn write(
        &self,
        writer: &mut impl std::fmt::Write,
        fall_back_to_debug: bool,
    ) -> crate::quil::ToQuilResult<()> {
        match &self.qubit {
            Some(qubit) => {
                write!(writer, "RESET ")?;
                qubit.write(writer, fall_back_to_debug)
            }
            None => write!(writer, "RESET").map_err(Into::into),
        }
    }
}