salsa/tests/no_send_sync.rs

34 lines
762 B
Rust
Raw Normal View History

2019-03-27 09:35:09 +00:00
extern crate salsa;
use std::rc::Rc;
#[salsa::query_group(NoSendSyncStorage)]
trait NoSendSyncDatabase: salsa::Database {
fn no_send_sync_value(&self, key: bool) -> Rc<bool>;
fn no_send_sync_key(&self, key: Rc<bool>) -> bool;
}
2019-03-27 09:35:09 +00:00
fn no_send_sync_value(_db: &dyn NoSendSyncDatabase, key: bool) -> Rc<bool> {
Rc::new(key)
2019-03-27 09:35:09 +00:00
}
fn no_send_sync_key(_db: &dyn NoSendSyncDatabase, key: Rc<bool>) -> bool {
*key
2019-03-27 09:35:09 +00:00
}
#[salsa::database(NoSendSyncStorage)]
2019-03-27 09:35:09 +00:00
#[derive(Default)]
struct DatabaseImpl {
2020-07-02 10:31:02 +00:00
storage: salsa::Storage<Self>,
2019-03-27 09:35:09 +00:00
}
2020-07-02 10:31:02 +00:00
impl salsa::Database for DatabaseImpl {}
2019-03-27 09:35:09 +00:00
#[test]
fn no_send_sync() {
2019-04-03 14:01:38 +00:00
let db = DatabaseImpl::default();
2019-03-27 09:35:09 +00:00
assert_eq!(db.no_send_sync_value(true), Rc::new(true));
2021-11-01 17:42:03 +00:00
assert!(!db.no_send_sync_key(Rc::new(false)));
2019-03-27 09:35:09 +00:00
}