On 12-10-21 09:50 PM, Benjamin Striegel wrote:
> If it's not too much trouble, a complete example (using any one of the
> proposed syntaxes) would be enlightening. I'm still having a hard time
> imagining how OutOfKittens is defined, and how do_some_stuff et al
> signal it in the first place, and how the input/output of OutOfKittens
> can be utilized within the signalling function.
Sure. Let's use a real case such as "trying to open a file that might be
missing in the middle of a call to read_whole_file_str". This involves a
few assumed changes to the way io is structured, but nothing deep:
// Boilerplate for declaring TLS key
fn missing_file_key(_x: @Handler<Path,Reader>) { }
const missing_file : Condition<Path,Reader> =
Condition { key: missing_file_key };
mod io {
// Revised to not use Result anymore
pub fn file_reader(path: &Path) -> Reader {
let f = do os::as_c_charp(path.to_str()) |p| {
do os::as_c_charp("r") |m| {
libc::fopen(p, m)
}
};
if f as uint == 0u {
// No such file; ask for help via .raise
missing_file.raise(path)
} else {
FILE_reader(f, true))
}
}
}
fn main() {
do missing_file.trap(|_p|
BytesReader { bytes: ~[], pos: 0u } as Reader
).in {
// This will trap in io::file_reader and
// substitute the empty bytes_reader above
let s = io::read_whole_file_str(Path("/nonexistent"));
}
}
Clear enough?
-Graydon
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev