This crate provides a simple way to use a string as an error trait object,
i.e. Box<std::error::Error>
.
If you need more sophisticated error handling, you should consider error-chain, which also provides functionality to create simple errors from Strings.
This crate works with Stable Rust (tested with 1.20.0) and has no dependencies.
Written by Ulrich Rhein, licensed under the Apache License 2.0.
See COPYRIGHT and LICENSE for details.
In your Cargo.toml
:
[dependencies]
string-error = "0.1.0"
In your code: ```rust extern crate string_error;
use std::error::Error; use stringerror::{intoerr, newerr, staticerr};
static ERROR_MESSAGE : &'static str = "This is a constant error message";
fn usestaticerr() -> Result<(), Box
fn usenewerr() -> Result<(), Box
fn useintoerr() -> Result<(), Box