[][src]Enum molt::types::ResultCode

pub enum ResultCode {
    Error(Value),
    Return(Value),
    Break,
    Continue,
}

This enum represents the possible exceptional results of evaluating a Molt script, as used in MoltResult. It is often used in the Result<_,ResultCode> type of other functions in the Molt API, so that these functions can easily return errors when used in the definition of Molt commands.

A Molt script can return a normal result, as indicated by MoltResult's Ok variant, or it can return one of a number of exceptional results, which will bubble up the call stack in the usual way until caught.

  • Error(Value): This code indicates a Molt error; the Value is the error message for display to the user. (But see "Future Work", below.)

  • Return(Value): This code indicates that a Molt procedure called the return command. The Value is the returned value, or the empty value if return was called without a return value. This result will bubble up until it reaches the top-level of the procedure, which will then return the value as a normal Ok result. If it is received when evaluating an arbitrary script, i.e., if return is called outside of any procedure, the interpreter will convert it into a normal Ok result.

  • Break: This code indicates a script called the Molt break command. It will break out of the inmost enclosing loop in the usual way. If it is returned outside a loop (or some user-defined control structure that supports break), the interpreter will convert it into an error.

  • Continue: This code indicates that a script called the Molt continue command. It will continue with the next iteration of the inmost enclosing loop in the usual way. If it is returned outside a loop (or some user-defined control structure that supports continue), the interpreter will convert it into an error.

Client code will usually see only the Error code; the others will most often be caught and handled within the interpreter. However, client code may explicitly catch and handle the Return, Break, and Continue codes at both the Rust and the TCL level (see the catch command) in order to implement application-specific control structures.

Future Work

  • Standard TCL includes more information with non-Ok results, especially for error cases. Ultimately, this type will be need to be extended to support that.

  • Standard TCL allows for an arbitrary number of result codes, which in turn allows the application to define an arbitrary number of new kinds of control structures that are distinct from the standard ones. At some point we might wish to add one or more generic result codes, parallel to Break and Continue, for this purpose. (However, in over two decades of TCL programming I've never seen the need to use generic result codes.)

Variants

Error(Value)
Return(Value)
Break
Continue

Methods

impl ResultCode[src]

pub fn is_error(&self) -> bool[src]

Indicates whether the result code is an Error.

Trait Implementations

impl Clone for ResultCode[src]

impl Debug for ResultCode[src]

impl Eq for ResultCode[src]

impl PartialEq<ResultCode> for ResultCode[src]

impl StructuralEq for ResultCode[src]

impl StructuralPartialEq for ResultCode[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.