From f42e78922df643fc7e873a451bb86353944391bb Mon Sep 17 00:00:00 2001 From: JonasDepoixSonos <137389421+JonasDepoixSonos@users.noreply.github.com> Date: Fri, 16 Aug 2024 18:09:23 +0200 Subject: [PATCH] fixed ConstFst ffi Trs iterator (#282) --- rustfst/src/trs.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/rustfst/src/trs.rs b/rustfst/src/trs.rs index b20ec1fcc..dbf4bd07b 100644 --- a/rustfst/src/trs.rs +++ b/rustfst/src/trs.rs @@ -77,7 +77,7 @@ impl Trs for TrsConst { } fn to_trs_vec(&self) -> TrsVec { - TrsVec(Arc::clone(&self.trs)) + TrsVec(Arc::new(self.trs().to_vec())) } // Doesn't clone the data, only the Arc @@ -116,3 +116,31 @@ impl Default for TrsConst { } } } + +#[cfg(test)] +mod tests { + use super::*; + + mod test_trs_const { + use super::*; + use crate::prelude::TropicalWeight; + use anyhow::Result; + + #[test] + fn test_to_trs_vec() -> Result<()> { + let trs = TrsConst { + trs: Arc::new(vec![ + Tr::::new(1, 1, TropicalWeight::one(), 0), + Tr::::new(1, 1, TropicalWeight::one(), 0), + ]), + pos: 1, + n: 1, + }; + + let tr_vec = trs.to_trs_vec(); + assert_eq!(tr_vec.len(), 1); + + Ok(()) + } + } +}