Enum ResultCode

Source
pub enum ResultCode {
    Okay,
    Error,
    Return,
    Break,
    Continue,
    Other(MoltInt),
}
Expand description

This enum represents the different kinds of Exception that result from evaluating a Molt script.

Client Rust 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 Break and Continue (or application-defined codes) at both the Rust and the TCL level in order to implement application-specific control structures. (See The Molt Book on the return and catch commands for more details on the TCL interface.)

Variants§

§

Okay

Value for return -code to indicate returning an Ok(value) higher up the stack. Client code should rarely if ever need to refer to this constant explicitly.

§

Error

A Molt error. The Exception::value is the error message for display to the user. The molt_err! and molt_throw! macros are usually used to produce errors in client code; but the Exception struct has a number of methods that give finer grained control.

§

Return

An explicit return from a Molt procedure. The Exception::value is the returned value, or the empty value if return was called without a return value. This result will bubble up through one or more stack levels (i.e., enclosing TCL procedure calls) and then yield 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.

Clients will rarely need to interact with or reference this result code explicitly, unless implementing application-specific control structures. See The Molt Book documentation for the return and catch command for the semantics.

§

Break

A break in a Molt loop. 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.

Clients will rarely need to interact with or reference this result code explicitly, unless implementing application-specific control structures. See The Molt Book documentation for the return and catch command for the semantics.

§

Continue

A continue in a Molt loop. Execution 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 break), the interpreter will convert it into an error.

Clients will rarely need to interact with or reference this result code explicitly, unless implementing application-specific control structures. See The Molt Book documentation for the return and catch command for the semantics.

§

Other(MoltInt)

A mechanism for defining application-specific result codes. Clients will rarely need to interact with or reference this result code explicitly, unless implementing application-specific control structures. See The Molt Book documentation for the return and catch command for the semantics.

Implementations§

Source§

impl ResultCode

Source

pub fn from_value(value: &Value) -> Result<Self, Exception>

A convenience: retrieves a result code string from the input Value the enumerated value as an external type, converting it from Option<ResultCode> into Result<ResultCode,Exception>.

This is primarily intended for use by the return command; if you really need it, you’d best be familiar with the implementation of return in command.rs, as well as a good bit of interp.rs.

Source

pub fn as_int(&self) -> MoltInt

Returns the result code as an integer.

This is primarily intended for use by the catch command.

Trait Implementations§

Source§

impl Clone for ResultCode

Source§

fn clone(&self) -> ResultCode

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ResultCode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ResultCode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats a result code for use with the return command’s -code option. This is part of making ResultCode a valid external type for use with Value.

Source§

impl FromStr for ResultCode

Source§

fn from_str(value: &str) -> Result<Self, Self::Err>

Converts a symbolic or numeric result code into a ResultCode. This is part of making ResultCode a valid external type for use with Value.

Source§

type Err = String

The associated error which can be returned from parsing.
Source§

impl PartialEq for ResultCode

Source§

fn eq(&self, other: &ResultCode) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for ResultCode

Source§

impl Eq for ResultCode

Source§

impl StructuralPartialEq for ResultCode

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

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

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.