#[salsa::input(jar = Jar)]
struct MyInput {
field1: u32,
field2: u32,
}
#[salsa::input(singleton)]
struct MySingletonInput {
field1: u32,
}
fn test_builder() {
let mut db = Database::default();
// durability set with new is always low
let mut input = MyInput::new(&db, 12, 13);
input
.set_field1(&mut db)
.with_durability(Durability::HIGH)
.to(20);
input
.set_field2(&mut db)
.with_durability(Durability::HIGH)
.to(40);
let input_from_builder = MyInput::new_builder()
.with_durability(Durability::HIGH)
.with_fields(20, 40)
.build(&db)
.unwrap();
assert_eq!(input.field1(&db), input_from_builder.field1(&db));
assert_eq!(input.field2(&db), input_from_builder.field2(&db));
}
On a more general note, ass suggested by #476, we should probably do this for all Salsa structs and fields:
#[salsa::input]
pub struct SourceProgram {
#[return_ref]
pub text: String,
#[return_ref]
pub path: PathBuf,
}
SourceProgram::build().with_text("text").with_path("foo.rs").finish()