cliprs 0.1.12

Rust bindings to CLIP.cpp
Documentation
use crate::ffi::{embed_compare, embed_image, embed_text, end, init};

#[cxx::bridge]
mod ffi {
    unsafe extern "C++" {
        include!("cliprs/clip.h");
        include!("cliprs/rust_interface.h");

        fn init(path: String);
        fn embed_text(text: String) -> Vec<f32>;
        fn embed_image(path: String) -> Vec<f32>;
        fn embed_compare(p1: &Vec<f32>, p2: &Vec<f32>) -> f32;
        fn end();
    }
}

pub fn cliprs_init(model_path: &str) {
    init(model_path.to_string());
}

pub fn cliprs_end() {
    end();
}

pub fn cliprs_embed_text(text: String) -> Option<Vec<f32>>{
    let vec = embed_text(text);

    if vec.len() == 0 {
        return None;
    }
    return Some(vec);
}

pub fn cliprs_embed_compare(p1: &Vec<f32>, p2: &Vec<f32>) -> f32{
    embed_compare(p1, p2)
}

pub fn cliprs_embed_image(path: String) -> Option<Vec<f32>>{
    let vec = embed_image(path);

    if vec.len() == 0 {
        return None;
    }
    return Some(vec);
}