ket/c_api/mod.rs
1// SPDX-FileCopyrightText: 2020 Evandro Chagas Ribeiro da Rosa <evandro@quantuloop.com>
2// SPDX-FileCopyrightText: 2020 Rafael de Santiago <r.santiago@ufsc.br>
3//
4// SPDX-License-Identifier: Apache-2.0
5
6//! C API Wrapper
7//!
8//! This module provides a wrapper C for the Rust functions.
9//!
10//! ## Error Handling
11//!
12//! The `ket_error_message` function allows retrieving error messages associated with error codes.
13//! Given an error code, it returns the corresponding error message string.
14//!
15//! # Safety
16//!
17//! Care should be taken when using C functions and data structures.
18
19pub mod error;
20pub mod execution;
21pub mod objects;
22pub mod process;
23
24/// Sets the log level for Libket.
25#[no_mangle]
26pub extern "C" fn ket_set_log_level(level: u32) -> i32 {
27 crate::util::set_log_level(level);
28 crate::prelude::KetError::Success.error_code()
29}
30
31const BUILD_INFO: &str = build_info::format!("{} v{} [{} {}]", $.crate_info.name, $.crate_info.version, $.compiler, $.target);
32
33#[no_mangle]
34pub extern "C" fn ket_build_info(msg: &mut *const u8, size: &mut usize) -> i32 {
35 let bytes = BUILD_INFO.as_bytes();
36 *size = bytes.len();
37 *msg = bytes.as_ptr();
38 crate::prelude::KetError::Success.error_code()
39}