Skip to main content

primer3_sys/
lib.rs

1//! Raw FFI bindings to the primer3 C library.
2//!
3//! This crate provides unsafe, low-level bindings generated by `bindgen`.
4//! Most users should use the `primer3` crate instead, which provides a safe,
5//! idiomatic Rust API on top of these bindings.
6
7#![allow(non_upper_case_globals)]
8#![allow(non_camel_case_types)]
9#![allow(non_snake_case)]
10#![allow(clippy::all, clippy::pub_underscore_fields)]
11
12include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
13
14// Manual FFI declarations for dpal (dynamic programming alignment).
15// bindgen cannot handle the `dpal_ssm` typedef (`int[UCHAR_MAX+1][UCHAR_MAX+1]`)
16// so we declare the types and functions manually.
17//
18// Re-exported at the crate root so callers use `primer3_sys::dpal_args` etc.
19#[allow(clippy::all)]
20mod dpal_ffi {
21    pub const DPAL_MAX_ALIGN: usize = 1600;
22    pub const DPAL_ERROR_SCORE: ::std::os::raw::c_int = ::std::os::raw::c_int::MIN;
23    pub const DPAL_LOCAL: ::std::os::raw::c_int = 0;
24    pub const DPAL_GLOBAL_END: ::std::os::raw::c_int = 1;
25    pub const DPAL_GLOBAL: ::std::os::raw::c_int = 2;
26    pub const DPAL_LOCAL_END: ::std::os::raw::c_int = 3;
27
28    pub type dpal_ssm = [[::std::os::raw::c_int; 256]; 256];
29
30    #[repr(C)]
31    pub struct dpal_args {
32        pub check_chars: ::std::os::raw::c_int,
33        pub fail_stop: ::std::os::raw::c_int,
34        pub flag: ::std::os::raw::c_int,
35        pub force_generic: ::std::os::raw::c_int,
36        pub force_long_generic: ::std::os::raw::c_int,
37        pub force_long_maxgap1: ::std::os::raw::c_int,
38        pub gap: ::std::os::raw::c_int,
39        pub gapl: ::std::os::raw::c_int,
40        pub max_gap: ::std::os::raw::c_int,
41        pub score_max: ::std::os::raw::c_int,
42        pub ssm: dpal_ssm,
43    }
44
45    #[repr(C)]
46    pub struct dpal_results {
47        pub msg: *const ::std::os::raw::c_char,
48        pub path: [[::std::os::raw::c_int; 2]; DPAL_MAX_ALIGN],
49        pub path_length: ::std::os::raw::c_int,
50        pub align_end_1: ::std::os::raw::c_int,
51        pub align_end_2: ::std::os::raw::c_int,
52        pub score: f64,
53        pub sec_struct: *mut ::std::os::raw::c_char,
54    }
55
56    pub const DPM_FAST: ::std::os::raw::c_int = 0;
57    pub const DPM_GENERAL: ::std::os::raw::c_int = 1;
58    pub const DPM_DEBUG: ::std::os::raw::c_int = 2;
59    pub const DPM_STRUCT: ::std::os::raw::c_int = 3;
60
61    unsafe extern "C" {
62        pub fn dpal_set_default_nt_args(a: *mut dpal_args);
63        pub fn dpal_set_h_nt_matrix(a: *mut dpal_args);
64        pub fn dpal_set_ambiguity_code_matrix(a: *mut dpal_args) -> ::std::os::raw::c_int;
65        pub fn set_dpal_args(a: *mut dpal_args);
66        pub fn dpal(
67            s1: *const ::std::os::raw::c_uchar,
68            s2: *const ::std::os::raw::c_uchar,
69            args: *const dpal_args,
70            mode: ::std::os::raw::c_int,
71            out: *mut dpal_results,
72        );
73    }
74}
75
76pub use dpal_ffi::*;