Skip to main content

bacon

Function bacon 

Source
pub fn bacon<T>(
    variable_name: &str,
    data: &mut T,
    variable_type: VariableType,
) -> Result<()>
Expand description

When the code reaches a variable that is watched, call this function to communicate synchronously with the link. It syncs with the other rats and gets the action to be taken for the current var. It then applies the action to the variable and returns.

Examples found in repository?
examples/rat2.rs (line 9)
1fn main() -> Result<(), Box<dyn std::error::Error>> {
2    env_logger::init();
3    let mut var = rat::rfalse();
4    let mut var3 = rat::rfalse();
5    let mut var4 = rat::rfalse();
6
7    rat::init("testRat2", None, None)?;
8
9    rat::bacon("var1", &mut var, mt_sea::VariableType::U8)?;
10    assert!(var == rat::rtrue());
11
12    rat::bacon("var3", &mut var3, mt_sea::VariableType::U8)?;
13    assert!(var3 == rat::rfalse());
14
15    rat::bacon("var4", &mut var4, mt_sea::VariableType::U8)?;
16    assert!(var4 == rat::rfalse());
17
18    rat::deinit()?;
19
20    let green = "\x1b[32m";
21    let reset = "\x1b[0m";
22    println!("\n{green}Success!{reset}");
23    Ok(())
24}
More examples
Hide additional examples
examples/rat1.rs (line 11)
1fn main() -> Result<(), Box<dyn std::error::Error>> {
2    env_logger::init();
3    let mut var1 = rat::rtrue();
4    let mut var2 = rat::rfalse();
5    let mut var3 = rat::rtrue();
6    let mut var4 = rat::rtrue();
7
8    rat::init("testRat1", None, None)?;
9
10    // exists on rat2
11    rat::bacon("var1", &mut var1, mt_sea::VariableType::U8)?;
12    assert!(var1 == rat::rtrue());
13
14    // does not exist, so should sail
15    rat::bacon("var2", &mut var2, mt_sea::VariableType::U8)?;
16    assert!(var2 == rat::rfalse());
17
18    rat::bacon("var3", &mut var3, mt_sea::VariableType::U8)?;
19    assert!(var3 == rat::rfalse());
20
21    rat::bacon("var4", &mut var4, mt_sea::VariableType::U8)?;
22    assert!(var4 == rat::rtrue());
23
24    rat::deinit()?;
25
26    let green = "\x1b[32m";
27    let reset = "\x1b[0m";
28    println!("\n{green}Success!{reset}");
29    Ok(())
30}