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 63 64 65 66 67 68 69 70
|
//! Test that the `constructor` macro overrides
//! the `new` method's name and `get` and `set`
//! change the name of the getter and setter of the fields.
#![allow(warnings)]
use std::fmt::Display;
use salsa::Setter;
#[salsa::db]
trait Db: salsa::Database {}
#[salsa::input(constructor = from_string)]
struct MyInput {
#[get(text)]
#[set(set_text)]
field: String,
}
impl MyInput {
pub fn new(db: &mut dyn Db, s: impl Display) -> MyInput {
MyInput::from_string(db, s.to_string())
}
pub fn field(self, db: &dyn Db) -> String {
self.text(db)
}
pub fn set_field(self, db: &mut dyn Db, id: String) {
self.set_text(db).to(id);
}
}
#[salsa::interned(constructor = from_string)]
struct MyInterned<'db> {
#[get(text)]
#[returns(ref)]
field: String,
}
impl<'db> MyInterned<'db> {
pub fn new(db: &'db dyn Db, s: impl Display) -> MyInterned<'db> {
MyInterned::from_string(db, s.to_string())
}
pub fn field(self, db: &'db dyn Db) -> &str {
&self.text(db)
}
}
#[salsa::tracked(constructor = from_string)]
struct MyTracked<'db> {
#[get(text)]
field: String,
}
impl<'db> MyTracked<'db> {
pub fn new(db: &'db dyn Db, s: impl Display) -> MyTracked<'db> {
MyTracked::from_string(db, s.to_string())
}
pub fn field(self, db: &'db dyn Db) -> String {
self.text(db)
}
}
#[test]
fn execute() {
salsa::DatabaseImpl::new();
}
|