qir_backend/
result_bool.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3#![deny(clippy::all, clippy::pedantic)]
4
5use qir_stdlib::strings::__quantum__rt__string_create;
6use std::ffi::{c_char, c_void, CString};
7
8#[no_mangle]
9pub extern "C" fn __quantum__rt__result_get_zero() -> *mut c_void {
10    std::ptr::null_mut()
11}
12
13#[no_mangle]
14pub extern "C" fn __quantum__rt__result_get_one() -> *mut c_void {
15    1 as *mut c_void
16}
17
18#[no_mangle]
19pub extern "C" fn __quantum__rt__result_equal(r1: *mut c_void, r2: *mut c_void) -> bool {
20    r1 == r2
21}
22
23#[no_mangle]
24pub extern "C" fn __quantum__rt__result_update_reference_count(_res: *mut c_void, _update: i32) {
25    // no-op
26}
27
28/// # Panics
29/// This function panics if the memory cannot be allocated for the result string.
30#[no_mangle]
31pub extern "C" fn __quantum__rt__result_to_string(res: *mut c_void) -> *const CString {
32    unsafe {
33        __quantum__rt__string_create(
34            CString::new(
35                if __quantum__rt__result_equal(res, __quantum__rt__result_get_one()) {
36                    "One"
37                } else {
38                    "Zero"
39                },
40            )
41            .expect("Failed to allocate memory for result string.")
42            .as_bytes_with_nul()
43            .as_ptr() as *mut c_char,
44        )
45    }
46}