adapton.rust
adapton.rust copied to clipboard
Hard to resolve error "set: Cannot mutate immutable Rc articulation; use an DCG cell instead"
Attempting to get a test working with the following code.
Not sure how to get the re-use and incremental compute working and I'm unsure of what the error message means (this is my first time using adapton).
Code sample:
#[test]
fn test_adapton_parser_pair() -> Result<(), TError> {
use adapton::*;
use std::sync::{Arc, Mutex};
let calls = Arc::new(Mutex::new(0));
let counter = calls.clone();
let input = cell!([input] "1,2");
let ast = thunk!([ast]
|src: &str| {
*counter.lock().unwrap() += 1;
setup(src)
};
src: get!(input)
);
{
set(&input, "1,2");
let ast = get!(ast)?;
assert_eq!(ast.identifiers.len(), 0);
assert_eq!(ast.literals.len(), 2);
assert_eq!(ast.ops.len(), 1);
assert_eq!(ast.definitions.len(), 0);
assert_eq!(*calls.lock().unwrap(), 1);
}
{
set(&input, "1,2,3");
let ast = get!(ast)?;
assert_eq!(ast.identifiers.len(), 0);
assert_eq!(ast.literals.len(), 3);
assert_eq!(ast.ops.len(), 2);
assert_eq!(ast.definitions.len(), 0);
assert_eq!(*calls.lock().unwrap(), 2);
}
{
set(&input, "1,2");
let ast = get!(ast)?;
assert_eq!(ast.identifiers.len(), 0);
assert_eq!(ast.literals.len(), 2);
assert_eq!(ast.ops.len(), 1);
assert_eq!(ast.definitions.len(), 0);
assert_eq!(*calls.lock().unwrap(), 2);
}
Ok(())
}
Would love some help with this as I'm fairly certain that I'm following the Adapton documentation (here: https://docs.rs/adapton/0.3.31/adapton/ ) fairly closely.
Thanks