rstm_rules/rule/
impl_learned_rule.rs1use super::LearnedRule;
7use crate::rule::Rule;
8use rstm_core::{Direction, Head, Tail};
9use rstm_state::RawState;
10
11impl<T, Q, S> LearnedRule<T, Q, S>
12where
13 Q: RawState,
14{
15 pub const fn new(head: Head<Q, S>, tail: Tail<Q, S>, confidence: T) -> Self {
17 Self {
18 confidence,
19 head,
20 tail,
21 }
22 }
23 pub fn from_rule(rule: Rule<Q, S>, confidence: T) -> Self {
25 Self::new(rule.head, rule.tail, confidence)
26 }
27 pub const fn from_parts(
29 state: Q,
30 symbol: S,
31 direction: Direction,
32 next_state: Q,
33 write_symbol: S,
34 confidence: T,
35 ) -> Self {
36 let head = Head::new(state, symbol);
38 let tail = Tail::new(direction, next_state, write_symbol);
39 Self::new(head, tail, confidence)
40 }
41 pub const fn confidence(&self) -> &T {
43 &self.confidence
44 }
45 pub const fn head(&self) -> Head<&Q, &S> {
47 self.head.view()
48 }
49 pub const fn head_mut(&mut self) -> Head<&mut Q, &mut S> {
51 self.head.view_mut()
52 }
53 pub const fn tail(&self) -> Tail<&Q, &S> {
55 self.tail.view()
56 }
57 pub const fn tail_mut(&mut self) -> Tail<&mut Q, &mut S> {
59 self.tail.view_mut()
60 }
61}
62
63impl<Q, S, T> From<Rule<Q, S>> for LearnedRule<T, Q, S>
64where
65 Q: RawState,
66 T: Default,
67{
68 fn from(rule: Rule<Q, S>) -> Self {
69 Self::new(rule.head, rule.tail, <T>::default())
70 }
71}