[−][src]Enum molt::types::ResultCode
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; theValue
is the error message for display to the user. (But see "Future Work", below.) -
Return(Value)
: This code indicates that a Molt procedure called thereturn
command. TheValue
is the returned value, or the empty value ifreturn
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 normalOk
result. If it is received when evaluating an arbitrary script, i.e., ifreturn
is called outside of any procedure, the interpreter will convert it into a normalOk
result. -
Break
: This code indicates a script called the Moltbreak
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 supportsbreak
), the interpreter will convert it into an error. -
Continue
: This code indicates that a script called the Moltcontinue
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 supportscontinue
), 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
andContinue
, 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)
Methods
impl ResultCode
[src]
Trait Implementations
impl Clone for ResultCode
[src]
fn clone(&self) -> ResultCode
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for ResultCode
[src]
impl Eq for ResultCode
[src]
impl PartialEq<ResultCode> for ResultCode
[src]
fn eq(&self, other: &ResultCode) -> bool
[src]
fn ne(&self, other: &ResultCode) -> bool
[src]
impl StructuralEq for ResultCode
[src]
impl StructuralPartialEq for ResultCode
[src]
Auto Trait Implementations
impl !RefUnwindSafe for ResultCode
impl !Send for ResultCode
impl !Sync for ResultCode
impl Unpin for ResultCode
impl !UnwindSafe for ResultCode
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,