salsa/tests/no_send_sync.rs

38 lines
873 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
2019-04-03 14:01:38 +00:00
fn no_send_sync_value(_db: &impl NoSendSyncDatabase, key: bool) -> Rc<bool> {
Rc::new(key)
2019-03-27 09:35:09 +00:00
}
2019-04-03 14:01:38 +00:00
fn no_send_sync_key(_db: &impl 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 {
runtime: salsa::Runtime<DatabaseImpl>,
}
impl salsa::Database for DatabaseImpl {
fn salsa_runtime(&self) -> &salsa::Runtime<DatabaseImpl> {
&self.runtime
}
}
#[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));
assert_eq!(db.no_send_sync_key(Rc::new(false)), false);
2019-03-27 09:35:09 +00:00
}