aboutsummaryrefslogtreecommitdiff
path: root/macros/src/check.rs
diff options
context:
space:
mode:
authorhomunkulus <homunkulus@gmx.com>2017-12-23 10:36:08 +0000
committerhomunkulus <homunkulus@gmx.com>2017-12-23 10:36:08 +0000
commit8a396c51f2caaeca7ee0f81ef2f3c4f2f73d8df1 (patch)
treefa6538343f2d524be574285c2bb68057edc11420 /macros/src/check.rs
parent0f5784c2401d4b12004f34345e721598fa21219a (diff)
parenta238fd5dc783f57f8fa61795690e6069b1becd32 (diff)
Auto merge of #58 - japaric:init-resources, r=japaric
safe `&'static mut` references via init.resources see RFC #59 for details
Diffstat (limited to 'macros/src/check.rs')
-rw-r--r--macros/src/check.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/macros/src/check.rs b/macros/src/check.rs
index 63cac1f..f6fd9cc 100644
--- a/macros/src/check.rs
+++ b/macros/src/check.rs
@@ -77,7 +77,38 @@ pub fn app(app: check::App) -> Result<App> {
}
fn resources(app: &App) -> Result<()> {
+ for name in &app.init.resources {
+ if let Some(resource) = app.resources.get(name) {
+ ensure!(
+ resource.expr.is_some(),
+ "resource `{}`, allocated to `init`, must have an initial value",
+ name
+ );
+ } else {
+ bail!(
+ "resource `{}`, allocated to `init`, must be a data resource",
+ name
+ );
+ }
+
+ ensure!(
+ !app.idle.resources.contains(name),
+ "resources assigned to `init` can't be shared with `idle`"
+ );
+
+ ensure!(
+ app.tasks
+ .iter()
+ .all(|(_, task)| !task.resources.contains(name)),
+ "resources assigned to `init` can't be shared with tasks"
+ )
+ }
+
for resource in app.resources.keys() {
+ if app.init.resources.contains(resource) {
+ continue;
+ }
+
if app.idle.resources.contains(resource) {
continue;
}