#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(improper_ctypes)]
#![allow(clippy::approx_constant)]
#![allow(clippy::type_complexity)]
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
#[cfg(test)]
mod tests {
use super::{
vrna_fold_compound, vrna_fold_compound_free, vrna_fold_compound_t, vrna_hamming_distance,
vrna_md_t, VRNA_OPTION_EVAL_ONLY, VRNA_VERSION,
};
use std::ffi::{CStr, CString};
use std::ptr::NonNull;
struct FoldCompound {
fc: NonNull<vrna_fold_compound_t>,
}
impl FoldCompound {
fn new(sequence: &str) -> Option<FoldCompound> {
let csequence = CString::new(sequence).expect("CString::new failed");
let fc = unsafe {
let md = std::ptr::null::<vrna_md_t>();
vrna_fold_compound(csequence.as_ptr(), md, VRNA_OPTION_EVAL_ONLY)
};
NonNull::new(fc).map(|fc| Self { fc })
}
}
impl Drop for FoldCompound {
fn drop(&mut self) {
unsafe {
vrna_fold_compound_free(self.fc.as_ptr());
}
}
}
pub fn hamming_distance(s1: &str, s2: &str) -> i32 {
let seq1 = CString::new(s1).expect("CString::new failed");
let seq2 = CString::new(s2).expect("CString::new failed");
unsafe { vrna_hamming_distance(seq1.as_ptr(), seq2.as_ptr()) }
}
#[test]
fn test_hamming() {
assert_eq!(hamming_distance("ACGUA", "ACGUC"), 1);
}
#[test]
fn test_link_openmp() {
let sequence = "GUACUGAUGUCGUAUACAGGGCUUUUGACAU";
let fc = FoldCompound::new(sequence);
assert!(fc.is_some());
}
#[test]
fn test_version_string() {
let version_string: Option<&str> = CStr::from_bytes_until_nul(VRNA_VERSION)
.ok()
.and_then(|v| v.to_str().ok());
assert!(version_string.is_some());
}
}