1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use crate::semirings::Semiring;
use crate::{Label, StateId};
/// Structure representing a transition from a state to another state in a FST.
#[derive(Debug, Clone, PartialEq)]
pub struct Arc<W: Semiring> {
/// Input label.
pub ilabel: Label,
/// Output label.
pub olabel: Label,
/// Weight.
pub weight: W,
/// ID of the next state.
pub nextstate: StateId,
}
impl<W: Semiring> Arc<W> {
/// Creates a new Arc.
///
/// # Example
///
/// ```
/// # use rustfst::Arc;
/// # use rustfst::semirings::{BooleanWeight, Semiring};
/// let arc = Arc::new(0, 1, BooleanWeight::one(), 2);
///
/// assert_eq!(arc.ilabel, 0);
/// assert_eq!(arc.olabel, 1);
/// assert_eq!(arc.weight, BooleanWeight::one());
/// assert_eq!(arc.nextstate, 2);
///
/// ```
pub fn new(ilabel: Label, olabel: Label, weight: W, nextstate: StateId) -> Self {
Arc {
ilabel,
olabel,
weight,
nextstate,
}
}
/// Updates the values of the attributes of the Arc from another Arc.
///
/// # Example
///
/// ```
/// # use rustfst::Arc;
/// # use rustfst::semirings::{BooleanWeight, Semiring};
/// let mut arc_1 = Arc::new(0, 1, BooleanWeight::one(), 2);
/// let arc_2 = Arc::new(1, 2, BooleanWeight::zero(), 3);
///
/// arc_1.set_value(&arc_2);
///
/// assert_eq!(arc_1, arc_2);
/// ```
pub fn set_value(&mut self, arc: &Arc<W>) {
self.ilabel = arc.ilabel;
self.olabel = arc.olabel;
self.weight = arc.weight.clone();
self.nextstate = arc.nextstate;
}
}