rustfst_ffi/algorithms/
isomorphic.rs

1use anyhow::anyhow;
2
3use crate::fst::CFst;
4use crate::{get, wrap, RUSTFST_FFI_RESULT};
5
6use rustfst::algorithms::isomorphic;
7use rustfst::fst_impls::VectorFst;
8use rustfst::semirings::TropicalWeight;
9
10/// # Safety
11///
12/// The pointers should be valid.
13#[no_mangle]
14pub unsafe fn fst_isomorphic(
15    fst: *const CFst,
16    other_fst: *const CFst,
17    is_isomorphic: *mut libc::size_t,
18) -> RUSTFST_FFI_RESULT {
19    wrap(|| {
20        let fst = get!(CFst, fst);
21        let other_fst = get!(CFst, other_fst);
22        let vec_fst: &VectorFst<TropicalWeight> = fst
23            .downcast_ref()
24            .ok_or_else(|| anyhow!("Could not downcast to vector FST"))?;
25        let other_vec_fst: &VectorFst<TropicalWeight> = other_fst
26            .downcast_ref()
27            .ok_or_else(|| anyhow!("Could not downcast to vector FST"))?;
28        let res = isomorphic(vec_fst, other_vec_fst)?;
29        unsafe { *is_isomorphic = res as usize }
30        Ok(())
31    })
32}