Skip to main content

rustfst_ffi/algorithms/
inversion.rs

1use anyhow::anyhow;
2
3use crate::fst::CFst;
4use crate::{get_mut, wrap, RUSTFST_FFI_RESULT};
5
6use rustfst::algorithms::invert;
7use rustfst::fst_impls::VectorFst;
8
9/// # Safety
10///
11/// The pointers should be valid.
12#[no_mangle]
13pub unsafe extern "C" fn fst_invert(ptr: *mut CFst) -> RUSTFST_FFI_RESULT {
14    wrap(|| {
15        let fst = get_mut!(CFst, ptr);
16        let vec_fst: &mut VectorFst<_> = fst
17            .downcast_mut()
18            .ok_or_else(|| anyhow!("Could not downcast to vector FST"))?;
19        invert(vec_fst);
20        Ok(())
21    })
22}