Thanks, this is very informative. I also have a few questions, so I
apologize in advance if I betray my ignorance.

The TLS key boilerplate would be rather unfortunate if it was forced to be
in both the API provider and the API consumer, would it be possible to
stick it in the io mod and then do

    const missing_file : Condition<Path,Reader> = Condition { key:
io::missing_file_key };

(Not sure if there's some limitation on consts that prevents this.)

I'm also unsure as to why missing_file_key needs to be a function at all,
nor why Condition needs to be a single-element struct. For example, would
it be possible for the io module to define an IoCondition enum, with
variants for all of its potential keys?

    const missing_file : IoCondition = MissingFile;

(I presume that there's some subtle point I'm missing here.)

Lastly, is it expected that rustdoc will learn to detect every time that
.raise() is called on a Condition? How will users of an API be expected to
discover all the possible signals that are available to be trapped from any
given function?





On Mon, Oct 22, 2012 at 9:44 PM, Graydon Hoare <[email protected]> wrote:

> 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
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to