pub struct Condition<T, U> { name: &'static str, key: Key<@Handler<T, U>>, }
This struct represents the state of a condition handler. It contains a key into TLS which holds the currently install handler, along with the name of the condition (useful for debugging).
This struct should never be created directly, but rather only through the
condition!
macro provided to all libraries using libstd.
impl<T, U> Condition<T, U>
fn trap<'a>(&'a self, h: &'a fn(T) -> U) -> Trap<'a, T, U>
Creates an object which binds the specified handler. This will also save
the current handler on creation such that when the Trap
is consumed,
it knows which handler to restore.
condition! { my_error: int -> int; }
let trap = my_error::cond.trap(|error| error + 3);
// use `trap`'s inside method to register the handler and then run a
// block of code with the handler registered
fn raise(&self, t: T) -> U
Raises on this condition, invoking any handler if one has been registered, or failing the current task otherwise.
While a condition handler is being run, the condition will have no handler listed, so a task failure will occur if the condition is re-raised during the handler.
If a handler is found, its return value is returned, otherwise this function will not return.
fn raise_default(&self, t: T, default: &fn() -> U) -> U
Performs the same functionality as raise
, except that when no handler
is found the default
argument is called instead of failing the task.
Prefix searches with a type followed by a colon (e.g.
fn:
) to restrict the search to a given type.
Accepted types are: fn
, mod
,
struct
(or str
), enum
,
trait
, typedef
(or
tdef
).