rustfst_ffi/algorithms/
concat.rs

1use anyhow::anyhow;
2
3use crate::fst::CFst;
4use crate::{get, get_mut, wrap, RUSTFST_FFI_RESULT};
5
6use rustfst::algorithms::concat::concat;
7use rustfst::fst_impls::VectorFst;
8use rustfst::semirings::TropicalWeight;
9
10/// # Safety
11///
12/// The pointers should be valid.
13#[no_mangle]
14pub unsafe extern "C" fn fst_concat(fst_1: *mut CFst, fst_2: *const CFst) -> RUSTFST_FFI_RESULT {
15    wrap(|| {
16        let fst_1 = get_mut!(CFst, fst_1);
17        let vec_fst1: &mut VectorFst<TropicalWeight> = fst_1
18            .downcast_mut()
19            .ok_or_else(|| anyhow!("Could not downcast to vector FST"))?;
20        let fst_2 = get!(CFst, fst_2);
21        let vec_fst2: &VectorFst<TropicalWeight> = fst_2
22            .downcast_ref()
23            .ok_or_else(|| anyhow!("Could not downcast to vector FST"))?;
24        concat(vec_fst1, vec_fst2)?;
25        Ok(())
26    })
27}