Files

21 lines
538 B
Rust

// expect: run
// result: 42
// grant: src=fs.read:/
// vfs: /input=*
// phase: 6
// spec: docs/spec/15-source-language.md
module test.source_balanced_close
fn close_on_both_paths(src: cap<fs.read>, first: bool) -> u64 effects [fs.read] {
let file = fs.open_read(src, b"/input") or trap;
if first {
fs.close(move file) or trap;
} else {
fs.close(move file) or trap;
}
21u64
}
fn main(src: cap<fs.read>) -> u64 effects [fs.read] {
close_on_both_paths(src, true) + close_on_both_paths(src, false)
}