Import quick-error 1.2.0 upstream upstream/1.2.0
authorDongHun Kwak <dh0128.kwak@samsung.com>
Tue, 9 May 2023 00:39:32 +0000 (09:39 +0900)
committerDongHun Kwak <dh0128.kwak@samsung.com>
Tue, 9 May 2023 00:39:32 +0000 (09:39 +0900)
.gitignore [new file with mode: 0644]
.travis.yml [new file with mode: 0644]
Cargo.toml [new file with mode: 0644]
LICENSE-APACHE [new file with mode: 0644]
LICENSE-MIT [new file with mode: 0644]
README.rst [new file with mode: 0644]
examples/context.rs [new file with mode: 0644]
src/lib.rs [new file with mode: 0644]
vagga.yaml [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..4cd31f5
--- /dev/null
@@ -0,0 +1,3 @@
+/.vagga
+/target
+/Cargo.lock
diff --git a/.travis.yml b/.travis.yml
new file mode 100644 (file)
index 0000000..b31686a
--- /dev/null
@@ -0,0 +1,21 @@
+language: rust
+rust:
+- stable
+- beta
+- nightly
+sudo: false
+env:
+  secure: "MG7A+O7VmpeofvsjCzawyvYE0NSS4MbAVYo6OYzTX4etlB4BAWuNfwDbkMs3yZev3m7Qb6Cts5PcV0fOVkdh4N/so9cPS3m6x9+MpTR7/ej/6sbyuSBEcMsxvtVzrmQt9pNvGcRYltId/KUl2cykwI0UrfFGOPwyjPAkQo//O0iJmnxiuakYD45wb+cbn2JOdbR94sn5BsdNw5pyOpsWsV3cmIoJqu/8EeVamQ09lQykRuC1OAMjGydp8zX+4agTC+WOoDLwU1OkyudJxy4ZrUD1hFHYOzHfjjhw4rpfi7XlrmyJUTcM4PVk2lvoE5TXwDlj6c1gcVFiXnSPi3Lr8Uo5P2ARaHvLDNNfl1S3U5PAA0p0lIcISDQBGzH698L6VsFKf2zQeOdUFh5o/81oe6pfDs9b1spQ4ANXibtUhioxaiWrR5CB/G5kvFbn9rG+IS8K198HTSZpG+hcNN343/xRpzpDarrQQmvhoGoevSXRO0OezJ+sKdxiPpYGGZtndmkHbvz0QwotfNlmdh/WIpV+o+Z1xK3Ic3G//lhhEfI+iBbebv3Hi7c3aFD/B3xTMowNkv4crru9CQDtyHB81di0N2okiMDGBz13zghsBdahoh9/PiT01ec0O6qrVLIiQfs3lzlxjr5ui2RNV1TCF8grS0lgSbriqm7x8uWZ4S4="
+script:
+- cargo build --verbose
+# don't run doc tests because they don't run well for macros
+- cargo test test --verbose
+after_success: |
+  [ $TRAVIS_RUST_VERSION = stable ] &&
+  [ $TRAVIS_BRANCH = master ] &&
+  [ $TRAVIS_PULL_REQUEST = false ] &&
+  cargo doc &&
+  echo "<meta http-equiv=refresh content=0;url=`echo $TRAVIS_REPO_SLUG | cut -d '/' -f 2 | tr '-' '_'`/index.html>" > target/doc/index.html &&
+  pip install ghp-import --user &&
+  ~/.local/bin/ghp-import -n target/doc &&
+  git push -fq https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644 (file)
index 0000000..92f9bbd
--- /dev/null
@@ -0,0 +1,13 @@
+[package]
+name = "quick-error"
+description = """
+    A macro which makes error types pleasant to write.
+"""
+license = "MIT/Apache-2.0"
+version = "1.2.0"
+keywords = ["macro", "error", "type", "enum"]
+authors = ["Paul Colomiets <paul@colomiets.name>", "Colin Kiegel <kiegel@gmx.de>"]
+homepage = "http://github.com/tailhook/quick-error"
+repository = "http://github.com/tailhook/quick-error"
+documentation = "http://tailhook.github.io/quick-error/"
+categories = ["rust-patterns"]
diff --git a/LICENSE-APACHE b/LICENSE-APACHE
new file mode 100644 (file)
index 0000000..8f71f43
--- /dev/null
@@ -0,0 +1,202 @@
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "{}"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright {yyyy} {name of copyright owner}
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
diff --git a/LICENSE-MIT b/LICENSE-MIT
new file mode 100644 (file)
index 0000000..14f715b
--- /dev/null
@@ -0,0 +1,19 @@
+Copyright (c) 2015 The quick-error Developers
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.rst b/README.rst
new file mode 100644 (file)
index 0000000..9b934a9
--- /dev/null
@@ -0,0 +1,69 @@
+===========
+Quick Error
+===========
+
+:Status: production-ready
+:Documentation: http://tailhook.github.io/quick-error/
+
+A macro which makes error types pleasant to write.
+
+Features:
+
+* Define enum type with arbitrary parameters
+* Concise notation of ``Display`` and ``Error`` traits
+* Full control of ``Display`` and ``Error`` trait implementation
+* Any number of ``From`` traits
+* Support for all enum-variants ``Unit``, ``Tuple`` and ``Struct``
+
+Here is the comprehensive example:
+
+.. code-block:: rust
+
+    quick_error! {
+        #[derive(Debug)]
+        pub enum IoWrapper {
+            Io(err: io::Error) {
+                from()
+                description("io error")
+                display("I/O error: {}", err)
+                cause(err)
+            }
+            Other(descr: &'static str) {
+                description(descr)
+                display("Error {}", descr)
+            }
+            IoAt { place: &'static str, err: io::Error } {
+                cause(err)
+                display(me) -> ("{} {}: {}", me.description(), place, err)
+                description("io error at")
+                from(s: String) -> {
+                    place: "some string",
+                    err: io::Error::new(io::ErrorKind::Other, s)
+                }
+            }
+            Discard {
+                from(&'static str)
+            }
+        }
+    }
+
+=======
+License
+=======
+
+Licensed under either of
+
+ * Apache License, Version 2.0, (./LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
+ * MIT license (./LICENSE-MIT or http://opensource.org/licenses/MIT)
+
+at your option.
+
+------------
+Contribution
+------------
+
+Unless you explicitly state otherwise, any contribution intentionally
+submitted for inclusion in the work by you, as defined in the Apache-2.0
+license, shall be dual licensed as above, without any additional terms or
+conditions.
+
diff --git a/examples/context.rs b/examples/context.rs
new file mode 100644 (file)
index 0000000..334700a
--- /dev/null
@@ -0,0 +1,48 @@
+#[macro_use(quick_error)] extern crate quick_error;
+
+use std::io::{self, stderr, Read, Write};
+use std::fs::File;
+use std::env;
+use std::num::ParseIntError;
+use std::path::{Path, PathBuf};
+
+use quick_error::ResultExt;
+
+quick_error! {
+    #[derive(Debug)]
+    pub enum Error {
+        NoFileName {
+            description("no file name specified")
+        }
+        Io(err: io::Error, path: PathBuf) {
+            display("could not read file {:?}: {}", path, err)
+            context(path: &'a Path, err: io::Error)
+                -> (err, path.to_path_buf())
+        }
+        Parse(err: ParseIntError, path: PathBuf) {
+            display("could not parse file {:?}: {}", path, err)
+            context(path: &'a Path, err: ParseIntError)
+                -> (err, path.to_path_buf())
+        }
+    }
+}
+
+fn parse_file() -> Result<u64, Error> {
+    let fname = try!(env::args().skip(1).next().ok_or(Error::NoFileName));
+    let fname = Path::new(&fname);
+    let mut file = try!(File::open(fname).context(fname));
+    let mut buf = String::new();
+    try!(file.read_to_string(&mut buf).context(fname));
+    Ok(try!(buf.parse().context(fname)))
+}
+
+fn main() {
+    match parse_file() {
+        Ok(val) => {
+            println!("Read: {}", val);
+        }
+        Err(e) => {
+            writeln!(&mut stderr(), "Error: {}", e).ok();
+        }
+    }
+}
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644 (file)
index 0000000..424eb01
--- /dev/null
@@ -0,0 +1,1293 @@
+#![warn(missing_docs)]
+//! A macro which makes errors easy to write
+//!
+//! Minimum type is like this:
+//!
+//! ```rust
+//! #[macro_use] extern crate quick_error;
+//! # fn main() {}
+//!
+//! quick_error! {
+//!     #[derive(Debug)]
+//!     pub enum SomeError {
+//!         Variant1 {}
+//!     }
+//! }
+//! ```
+//! Both ``pub`` and non-public types may be declared, and all meta attributes
+//! (such as ``#[derive(Debug)]``) are forwarded as is. The `Debug` must be
+//! implemented (but you may do that yourself if you like). The documentation
+//! comments ``/// something`` (as well as other meta attrbiutes) on variants
+//! are allowed.
+//!
+//! # Allowed Syntax
+//!
+//! You may add arbitrary parameters to any struct variant:
+//!
+//! ```rust
+//! # #[macro_use] extern crate quick_error;
+//! # fn main() {}
+//! #
+//! quick_error! {
+//!     #[derive(Debug)]
+//!     pub enum SomeError {
+//!         /// IO Error
+//!         Io(err: std::io::Error) {}
+//!         /// Utf8 Error
+//!         Utf8(err: std::str::Utf8Error) {}
+//!     }
+//! }
+//! ```
+//!
+//! Note unlike in normal Enum declarations you declare names of fields (which
+//! are omitted from type). How they can be used is outlined below.
+//!
+//! Now you might have noticed trailing braces `{}`. They are used to define
+//! implementations. By default:
+//!
+//! * `Error::description()` returns variant name as static string
+//! * `Error::cause()` returns None (even if type wraps some value)
+//! * `Display` outputs `description()`
+//! * No `From` implementations are defined
+//!
+//! To define description simply add `description(value)` inside braces:
+//!
+//! ```rust
+//! # #[macro_use] extern crate quick_error;
+//! # fn main() {}
+//! #
+//! quick_error! {
+//!     #[derive(Debug)]
+//!     pub enum SomeError {
+//!         Io(err: std::io::Error) {
+//!             description(err.description())
+//!         }
+//!         Utf8(err: std::str::Utf8Error) {
+//!             description("utf8 error")
+//!         }
+//!     }
+//! }
+//! ```
+//!
+//! Normal rules for borrowing apply. So most of the time description either
+//! returns constant string or forwards description from enclosed type.
+//!
+//! To change `cause` method to return some error, add `cause(value)`, for
+//! example:
+//!
+//! ```rust
+//! # #[macro_use] extern crate quick_error;
+//! # fn main() {}
+//! #
+//! quick_error! {
+//!     #[derive(Debug)]
+//!     pub enum SomeError {
+//!         Io(err: std::io::Error) {
+//!             cause(err)
+//!             description(err.description())
+//!         }
+//!         Utf8(err: std::str::Utf8Error) {
+//!             description("utf8 error")
+//!         }
+//!         Other(err: Box<std::error::Error>) {
+//!             cause(&**err)
+//!             description(err.description())
+//!         }
+//!     }
+//! }
+//! ```
+//! Note you don't need to wrap value in `Some`, its implicit. In case you want
+//! `None` returned just omit the `cause`. You can't return `None`
+//! conditionally.
+//!
+//! To change how each clause is `Display`ed add `display(pattern,..args)`,
+//! for example:
+//!
+//! ```rust
+//! # #[macro_use] extern crate quick_error;
+//! # fn main() {}
+//! #
+//! quick_error! {
+//!     #[derive(Debug)]
+//!     pub enum SomeError {
+//!         Io(err: std::io::Error) {
+//!             display("I/O error: {}", err)
+//!         }
+//!         Utf8(err: std::str::Utf8Error) {
+//!             display("Utf8 error, valid up to {}", err.valid_up_to())
+//!         }
+//!     }
+//! }
+//! ```
+//!
+//! If you need a reference to the error when `Display`ing, you can instead use
+//! `display(x) -> (pattern, ..args)`, where `x` sets the name of the reference.
+//!
+//! ```rust
+//! # #[macro_use] extern crate quick_error;
+//! # fn main() {}
+//! #
+//! use std::error::Error; // put methods like `description()` of this trait into scope
+//!
+//! quick_error! {
+//!     #[derive(Debug)]
+//!     pub enum SomeError {
+//!         Io(err: std::io::Error) {
+//!             display(x) -> ("{}: {}", x.description(), err)
+//!         }
+//!         Utf8(err: std::str::Utf8Error) {
+//!             display(self_) -> ("{}, valid up to {}", self_.description(), err.valid_up_to())
+//!         }
+//!     }
+//! }
+//! ```
+//!
+//! To convert to the type from any other, use one of the three forms of
+//! `from` clause.
+//!
+//! For example, to convert simple wrapper use bare `from()`:
+//!
+//! ```rust
+//! # #[macro_use] extern crate quick_error;
+//! # fn main() {}
+//! #
+//! quick_error! {
+//!     #[derive(Debug)]
+//!     pub enum SomeError {
+//!         Io(err: std::io::Error) {
+//!             from()
+//!         }
+//!     }
+//! }
+//! ```
+//!
+//! This implements ``From<io::Error>``.
+//!
+//! To convert to singleton enumeration type (discarding the value), use
+//! the `from(type)` form:
+//!
+//! ```rust
+//! # #[macro_use] extern crate quick_error;
+//! # fn main() {}
+//! #
+//! quick_error! {
+//!     #[derive(Debug)]
+//!     pub enum SomeError {
+//!         FormatError {
+//!             from(std::fmt::Error)
+//!         }
+//!     }
+//! }
+//! ```
+//!
+//! And the most powerful form is `from(var: type) -> (arguments...)`. It
+//! might be used to convert to type with multiple arguments or for arbitrary
+//! value conversions:
+//!
+//! ```rust
+//! # #[macro_use] extern crate quick_error;
+//! # fn main() {}
+//! #
+//! quick_error! {
+//!     #[derive(Debug)]
+//!     pub enum SomeError {
+//!         FailedOperation(s: &'static str, errno: i32) {
+//!             from(errno: i32) -> ("os error", errno)
+//!             from(e: std::io::Error) -> ("io error", e.raw_os_error().unwrap())
+//!         }
+//!         /// Converts from both kinds of utf8 errors
+//!         Utf8(err: std::str::Utf8Error) {
+//!             from()
+//!             from(err: std::string::FromUtf8Error) -> (err.utf8_error())
+//!         }
+//!     }
+//! }
+//! ```
+//! # Context
+//!
+//! Since quick-error 1.1 we also have a `context` declaration, which is
+//! similar to (the longest form of) `from`, but allows adding some context to
+//! the error. We need a longer example to demonstrate this:
+//!
+//! ```rust
+//! # #[macro_use] extern crate quick_error;
+//! # use std::io;
+//! # use std::fs::File;
+//! # use std::path::{Path, PathBuf};
+//! #
+//! use quick_error::ResultExt;
+//!
+//! quick_error! {
+//!     #[derive(Debug)]
+//!     pub enum Error {
+//!         File(filename: PathBuf, err: io::Error) {
+//!             context(path: &'a Path, err: io::Error)
+//!                 -> (path.to_path_buf(), err)
+//!         }
+//!     }
+//! }
+//!
+//! fn openfile(path: &Path) -> Result<(), Error> {
+//!     try!(File::open(path).context(path));
+//!
+//!     // If we didn't have context, the line above would be written as;
+//!     //
+//!     // try!(File::open(path)
+//!     //     .map_err(|err| Error::File(path.to_path_buf(), err)));
+//!
+//!     Ok(())
+//! }
+//!
+//! # fn main() {
+//! #     openfile(Path::new("/etc/somefile")).ok();
+//! # }
+//! ```
+//!
+//! Each `context(a: A, b: B)` clause implements
+//! `From<Context<A, B>> for Error`. Which means multiple `context` clauses
+//! are a subject to the normal coherence rules. Unfortunately, we can't
+//! provide full support of generics for the context, but you may either use a
+//! lifetime `'a` for references or `AsRef<Type>` (the latter means `A:
+//! AsRef<Type>`, and `Type` must be concrete). It's also occasionally useful
+//! to use a tuple as a type of the first argument.
+//!
+//! You also need to `use quick_error::ResultExt` extension trait to get
+//! working `.context()` method.
+//!
+//! More info on context in [this article](http://bit.ly/1PsuxDt).
+//!
+//! All forms of `from`, `display`, `description`, `cause`, and `context`
+//! clauses can be combined and put in arbitrary order. Only `from` and
+//! `context` can be used multiple times in single variant of enumeration.
+//! Docstrings are also okay.  Empty braces can be omitted as of quick_error
+//! 0.1.3.
+//!
+//! # Private Enums
+//!
+//! Since quick-error 1.2.0 we  have a way to make a private enum that is
+//! wrapped by public structure:
+//!
+//! ```rust
+//! #[macro_use] extern crate quick_error;
+//! # fn main() {}
+//!
+//! quick_error! {
+//!     #[derive(Debug)]
+//!     pub enum PubError wraps ErrorEnum {
+//!         Variant1 {}
+//!     }
+//! }
+//! ```
+//!
+//! This generates data structures like this
+//!
+//! ```rust
+//!
+//! pub struct PubError(ErrorEnum);
+//!
+//! enum ErrorEnum {
+//!     Variant1,
+//! }
+//!
+//! ```
+//!
+//! Which in turn allows you to export just `PubError` in your crate and keep
+//! actual enumeration private to the crate. This is useful to keep backwards
+//! compatibility for error types. Currently there is no shorcuts to define
+//! error constructors for the inner type, but we consider adding some in
+//! future versions.
+//!
+//! It's possible to declare internal enum as public too.
+//!
+//!
+
+
+/// Main macro that does all the work
+#[macro_export]
+macro_rules! quick_error {
+
+    (   $(#[$meta:meta])*
+        pub enum $name:ident { $($chunks:tt)* }
+    ) => {
+        quick_error!(SORT [pub enum $name $(#[$meta])* ]
+            items [] buf []
+            queue [ $($chunks)* ]);
+    };
+    (   $(#[$meta:meta])*
+        enum $name:ident { $($chunks:tt)* }
+    ) => {
+        quick_error!(SORT [enum $name $(#[$meta])* ]
+            items [] buf []
+            queue [ $($chunks)* ]);
+    };
+
+    (   $(#[$meta:meta])*
+        pub enum $name:ident wraps $enum_name:ident { $($chunks:tt)* }
+    ) => {
+        quick_error!(WRAPPER $enum_name [ pub struct ] $name $(#[$meta])*);
+        quick_error!(SORT [enum $enum_name $(#[$meta])* ]
+            items [] buf []
+            queue [ $($chunks)* ]);
+    };
+
+    (   $(#[$meta:meta])*
+        pub enum $name:ident wraps pub $enum_name:ident { $($chunks:tt)* }
+    ) => {
+        quick_error!(WRAPPER $enum_name [ pub struct ] $name $(#[$meta])*);
+        quick_error!(SORT [pub enum $enum_name $(#[$meta])* ]
+            items [] buf []
+            queue [ $($chunks)* ]);
+    };
+    (   $(#[$meta:meta])*
+        enum $name:ident wraps $enum_name:ident { $($chunks:tt)* }
+    ) => {
+        quick_error!(WRAPPER $enum_name [ struct ] $name $(#[$meta])*);
+        quick_error!(SORT [enum $enum_name $(#[$meta])* ]
+            items [] buf []
+            queue [ $($chunks)* ]);
+    };
+
+    (   $(#[$meta:meta])*
+        enum $name:ident wraps pub $enum_name:ident { $($chunks:tt)* }
+    ) => {
+        quick_error!(WRAPPER $enum_name [ struct ] $name $(#[$meta])*);
+        quick_error!(SORT [pub enum $enum_name $(#[$meta])* ]
+            items [] buf []
+            queue [ $($chunks)* ]);
+    };
+
+
+    (
+        WRAPPER $internal:ident [ $($strdef:tt)* ] $strname:ident
+        $(#[$meta:meta])*
+    ) => {
+        $(#[$meta])*
+        $($strdef)* $strname ( $internal );
+
+        impl ::std::fmt::Display for $strname {
+            fn fmt(&self, f: &mut ::std::fmt::Formatter)
+                -> ::std::fmt::Result
+            {
+                ::std::fmt::Display::fmt(&self.0, f)
+            }
+        }
+
+        impl From<$internal> for $strname {
+            fn from(err: $internal) -> Self {
+                $strname(err)
+            }
+        }
+
+        impl ::std::error::Error for $strname {
+            fn description(&self) -> &str {
+                self.0.description()
+            }
+            fn cause(&self) -> Option<&::std::error::Error> {
+                self.0.cause()
+            }
+        }
+    };
+
+    // Queue is empty, can do the work
+    (SORT [enum $name:ident $( #[$meta:meta] )*]
+        items [$($( #[$imeta:meta] )*
+                  => $iitem:ident: $imode:tt [$( $ivar:ident: $ityp:ty ),*]
+                                {$( $ifuncs:tt )*} )* ]
+        buf [ ]
+        queue [ ]
+    ) => {
+        quick_error!(ENUM_DEFINITION [enum $name $( #[$meta] )*]
+            body []
+            queue [$($( #[$imeta] )*
+                      => $iitem: $imode [$( $ivar: $ityp ),*] )*]
+        );
+        quick_error!(IMPLEMENTATIONS $name {$(
+           $iitem: $imode [$(#[$imeta])*] [$( $ivar: $ityp ),*] {$( $ifuncs )*}
+           )*});
+        $(
+            quick_error!(ERROR_CHECK $imode $($ifuncs)*);
+        )*
+    };
+    (SORT [pub enum $name:ident $( #[$meta:meta] )*]
+        items [$($( #[$imeta:meta] )*
+                  => $iitem:ident: $imode:tt [$( $ivar:ident: $ityp:ty ),*]
+                                {$( $ifuncs:tt )*} )* ]
+        buf [ ]
+        queue [ ]
+    ) => {
+        quick_error!(ENUM_DEFINITION [pub enum $name $( #[$meta] )*]
+            body []
+            queue [$($( #[$imeta] )*
+                      => $iitem: $imode [$( $ivar: $ityp ),*] )*]
+        );
+        quick_error!(IMPLEMENTATIONS $name {$(
+           $iitem: $imode [$(#[$imeta])*] [$( $ivar: $ityp ),*] {$( $ifuncs )*}
+           )*});
+        $(
+            quick_error!(ERROR_CHECK $imode $($ifuncs)*);
+        )*
+    };
+    // Add meta to buffer
+    (SORT [$( $def:tt )*]
+        items [$($( #[$imeta:meta] )*
+                  => $iitem:ident: $imode:tt [$( $ivar:ident: $ityp:ty ),*]
+                                {$( $ifuncs:tt )*} )* ]
+        buf [$( #[$bmeta:meta] )*]
+        queue [ #[$qmeta:meta] $( $tail:tt )*]
+    ) => {
+        quick_error!(SORT [$( $def )*]
+            items [$( $(#[$imeta])* => $iitem: $imode [$( $ivar:$ityp ),*] {$( $ifuncs )*} )*]
+            buf [$( #[$bmeta] )* #[$qmeta] ]
+            queue [$( $tail )*]);
+    };
+    // Add ident to buffer
+    (SORT [$( $def:tt )*]
+        items [$($( #[$imeta:meta] )*
+                  => $iitem:ident: $imode:tt [$( $ivar:ident: $ityp:ty ),*]
+                                {$( $ifuncs:tt )*} )* ]
+        buf [$( #[$bmeta:meta] )*]
+        queue [ $qitem:ident $( $tail:tt )*]
+    ) => {
+        quick_error!(SORT [$( $def )*]
+            items [$( $(#[$imeta])*
+                      => $iitem: $imode [$( $ivar:$ityp ),*] {$( $ifuncs )*} )*]
+            buf [$(#[$bmeta])* => $qitem : UNIT [ ] ]
+            queue [$( $tail )*]);
+    };
+    // Flush buffer on meta after ident
+    (SORT [$( $def:tt )*]
+        items [$($( #[$imeta:meta] )*
+                  => $iitem:ident: $imode:tt [$( $ivar:ident: $ityp:ty ),*]
+                                {$( $ifuncs:tt )*} )* ]
+        buf [$( #[$bmeta:meta] )*
+            => $bitem:ident: $bmode:tt [$( $bvar:ident: $btyp:ty ),*] ]
+        queue [ #[$qmeta:meta] $( $tail:tt )*]
+    ) => {
+        quick_error!(SORT [$( $def )*]
+            enum [$( $(#[$emeta])* => $eitem $(( $($etyp),* ))* )*
+                     $(#[$bmeta])* => $bitem: $bmode $(( $($btyp),* ))*]
+            items [$($( #[$imeta:meta] )*
+                      => $iitem: $imode [$( $ivar:$ityp ),*] {$( $ifuncs )*} )*
+                     $bitem: $bmode [$( $bvar:$btyp ),*] {} ]
+            buf [ #[$qmeta] ]
+            queue [$( $tail )*]);
+    };
+    // Add tuple enum-variant
+    (SORT [$( $def:tt )*]
+        items [$($( #[$imeta:meta] )*
+                  => $iitem:ident: $imode:tt [$( $ivar:ident: $ityp:ty ),*]
+                                {$( $ifuncs:tt )*} )* ]
+        buf [$( #[$bmeta:meta] )* => $bitem:ident: UNIT [ ] ]
+        queue [($( $qvar:ident: $qtyp:ty ),+) $( $tail:tt )*]
+    ) => {
+        quick_error!(SORT [$( $def )*]
+            items [$( $(#[$imeta])* => $iitem: $imode [$( $ivar:$ityp ),*] {$( $ifuncs )*} )*]
+            buf [$( #[$bmeta] )* => $bitem: TUPLE [$( $qvar:$qtyp ),*] ]
+            queue [$( $tail )*]
+        );
+    };
+    // Add struct enum-variant - e.g. { descr: &'static str }
+    (SORT [$( $def:tt )*]
+        items [$($( #[$imeta:meta] )*
+                  => $iitem:ident: $imode:tt [$( $ivar:ident: $ityp:ty ),*]
+                                {$( $ifuncs:tt )*} )* ]
+        buf [$( #[$bmeta:meta] )* => $bitem:ident: UNIT [ ] ]
+        queue [{ $( $qvar:ident: $qtyp:ty ),+} $( $tail:tt )*]
+    ) => {
+        quick_error!(SORT [$( $def )*]
+            items [$( $(#[$imeta])* => $iitem: $imode [$( $ivar:$ityp ),*] {$( $ifuncs )*} )*]
+            buf [$( #[$bmeta] )* => $bitem: STRUCT [$( $qvar:$qtyp ),*] ]
+            queue [$( $tail )*]);
+    };
+    // Add struct enum-variant, with excess comma - e.g. { descr: &'static str, }
+    (SORT [$( $def:tt )*]
+        items [$($( #[$imeta:meta] )*
+                  => $iitem:ident: $imode:tt [$( $ivar:ident: $ityp:ty ),*]
+                                {$( $ifuncs:tt )*} )* ]
+        buf [$( #[$bmeta:meta] )* => $bitem:ident: UNIT [ ] ]
+        queue [{$( $qvar:ident: $qtyp:ty ),+ ,} $( $tail:tt )*]
+    ) => {
+        quick_error!(SORT [$( $def )*]
+            items [$( $(#[$imeta])* => $iitem: $imode [$( $ivar:$ityp ),*] {$( $ifuncs )*} )*]
+            buf [$( #[$bmeta] )* => $bitem: STRUCT [$( $qvar:$qtyp ),*] ]
+            queue [$( $tail )*]);
+    };
+    // Add braces and flush always on braces
+    (SORT [$( $def:tt )*]
+        items [$($( #[$imeta:meta] )*
+                  => $iitem:ident: $imode:tt [$( $ivar:ident: $ityp:ty ),*]
+                                {$( $ifuncs:tt )*} )* ]
+        buf [$( #[$bmeta:meta] )*
+                 => $bitem:ident: $bmode:tt [$( $bvar:ident: $btyp:ty ),*] ]
+        queue [ {$( $qfuncs:tt )*} $( $tail:tt )*]
+    ) => {
+        quick_error!(SORT [$( $def )*]
+            items [$( $(#[$imeta])* => $iitem: $imode [$( $ivar:$ityp ),*] {$( $ifuncs )*} )*
+                      $(#[$bmeta])* => $bitem: $bmode [$( $bvar:$btyp ),*] {$( $qfuncs )*} ]
+            buf [ ]
+            queue [$( $tail )*]);
+    };
+    // Flush buffer on double ident
+    (SORT [$( $def:tt )*]
+        items [$($( #[$imeta:meta] )*
+                  => $iitem:ident: $imode:tt [$( $ivar:ident: $ityp:ty ),*]
+                                {$( $ifuncs:tt )*} )* ]
+        buf [$( #[$bmeta:meta] )*
+                 => $bitem:ident: $bmode:tt [$( $bvar:ident: $btyp:ty ),*] ]
+        queue [ $qitem:ident $( $tail:tt )*]
+    ) => {
+        quick_error!(SORT [$( $def )*]
+            items [$( $(#[$imeta])* => $iitem: $imode [$( $ivar:$ityp ),*] {$( $ifuncs )*} )*
+                     $(#[$bmeta])* => $bitem: $bmode [$( $bvar:$btyp ),*] {} ]
+            buf [ => $qitem : UNIT [ ] ]
+            queue [$( $tail )*]);
+    };
+    // Flush buffer on end
+    (SORT [$( $def:tt )*]
+        items [$($( #[$imeta:meta] )*
+                  => $iitem:ident: $imode:tt [$( $ivar:ident: $ityp:ty ),*]
+                                {$( $ifuncs:tt )*} )* ]
+        buf [$( #[$bmeta:meta] )*
+            => $bitem:ident: $bmode:tt [$( $bvar:ident: $btyp:ty ),*] ]
+        queue [ ]
+    ) => {
+        quick_error!(SORT [$( $def )*]
+            items [$( $(#[$imeta])* => $iitem: $imode [$( $ivar:$ityp ),*] {$( $ifuncs )*} )*
+                     $(#[$bmeta])* => $bitem: $bmode [$( $bvar:$btyp ),*] {} ]
+            buf [ ]
+            queue [ ]);
+    };
+    // Public enum (Queue Empty)
+    (ENUM_DEFINITION [pub enum $name:ident $( #[$meta:meta] )*]
+        body [$($( #[$imeta:meta] )*
+            => $iitem:ident ($(($( $ttyp:ty ),+))*) {$({$( $svar:ident: $styp:ty ),*})*} )* ]
+        queue [ ]
+    ) => {
+        $(#[$meta])*
+        pub enum $name {
+            $(
+                $(#[$imeta])*
+                $iitem $(($( $ttyp ),*))* $({$( $svar: $styp ),*})*,
+            )*
+        }
+    };
+    // Private enum (Queue Empty)
+    (ENUM_DEFINITION [enum $name:ident $( #[$meta:meta] )*]
+        body [$($( #[$imeta:meta] )*
+            => $iitem:ident ($(($( $ttyp:ty ),+))*) {$({$( $svar:ident: $styp:ty ),*})*} )* ]
+        queue [ ]
+    ) => {
+        $(#[$meta])*
+        enum $name {
+            $(
+                $(#[$imeta])*
+                $iitem $(($( $ttyp ),*))* $({$( $svar: $styp ),*})*,
+            )*
+        }
+    };
+    // Unit variant
+    (ENUM_DEFINITION [$( $def:tt )*]
+        body [$($( #[$imeta:meta] )*
+            => $iitem:ident ($(($( $ttyp:ty ),+))*) {$({$( $svar:ident: $styp:ty ),*})*} )* ]
+        queue [$( #[$qmeta:meta] )*
+            => $qitem:ident: UNIT [ ] $( $queue:tt )*]
+    ) => {
+        quick_error!(ENUM_DEFINITION [ $($def)* ]
+            body [$($( #[$imeta] )* => $iitem ($(($( $ttyp ),+))*) {$({$( $svar: $styp ),*})*} )*
+                    $( #[$qmeta] )* => $qitem () {} ]
+            queue [ $($queue)* ]
+        );
+    };
+    // Tuple variant
+    (ENUM_DEFINITION [$( $def:tt )*]
+        body [$($( #[$imeta:meta] )*
+            => $iitem:ident ($(($( $ttyp:ty ),+))*) {$({$( $svar:ident: $styp:ty ),*})*} )* ]
+        queue [$( #[$qmeta:meta] )*
+            => $qitem:ident: TUPLE [$( $qvar:ident: $qtyp:ty ),+] $( $queue:tt )*]
+    ) => {
+        quick_error!(ENUM_DEFINITION [ $($def)* ]
+            body [$($( #[$imeta] )* => $iitem ($(($( $ttyp ),+))*) {$({$( $svar: $styp ),*})*} )*
+                    $( #[$qmeta] )* => $qitem (($( $qtyp ),*)) {} ]
+            queue [ $($queue)* ]
+        );
+    };
+    // Struct variant
+    (ENUM_DEFINITION [$( $def:tt )*]
+        body [$($( #[$imeta:meta] )*
+            => $iitem:ident ($(($( $ttyp:ty ),+))*) {$({$( $svar:ident: $styp:ty ),*})*} )* ]
+        queue [$( #[$qmeta:meta] )*
+            => $qitem:ident: STRUCT [$( $qvar:ident: $qtyp:ty ),*] $( $queue:tt )*]
+    ) => {
+        quick_error!(ENUM_DEFINITION [ $($def)* ]
+            body [$($( #[$imeta] )* => $iitem ($(($( $ttyp ),+))*) {$({$( $svar: $styp ),*})*} )*
+                    $( #[$qmeta] )* => $qitem () {{$( $qvar: $qtyp ),*}} ]
+            queue [ $($queue)* ]
+        );
+    };
+    (IMPLEMENTATIONS
+        $name:ident {$(
+            $item:ident: $imode:tt [$(#[$imeta:meta])*] [$( $var:ident: $typ:ty ),*] {$( $funcs:tt )*}
+        )*}
+    ) => {
+        #[allow(unused)]
+        impl ::std::fmt::Display for $name {
+            fn fmt(&self, fmt: &mut ::std::fmt::Formatter)
+                -> ::std::fmt::Result
+            {
+                match *self {
+                    $(
+                        $(#[$imeta])*
+                        quick_error!(ITEM_PATTERN
+                            $name $item: $imode [$( ref $var ),*]
+                        ) => {
+                            let display_fn = quick_error!(FIND_DISPLAY_IMPL
+                                $name $item: $imode
+                                {$( $funcs )*});
+
+                            display_fn(self, fmt)
+                        }
+                    )*
+                }
+            }
+        }
+        #[allow(unused)]
+        impl ::std::error::Error for $name {
+            fn description(&self) -> &str {
+                match *self {
+                    $(
+                        $(#[$imeta])*
+                        quick_error!(ITEM_PATTERN
+                            $name $item: $imode [$( ref $var ),*]
+                        ) => {
+                            quick_error!(FIND_DESCRIPTION_IMPL
+                                $item: $imode self fmt [$( $var ),*]
+                                {$( $funcs )*})
+                        }
+                    )*
+                }
+            }
+            fn cause(&self) -> Option<&::std::error::Error> {
+                match *self {
+                    $(
+                        $(#[$imeta])*
+                        quick_error!(ITEM_PATTERN
+                            $name $item: $imode [$( ref $var ),*]
+                        ) => {
+                            quick_error!(FIND_CAUSE_IMPL
+                                $item: $imode [$( $var ),*]
+                                {$( $funcs )*})
+                        }
+                    )*
+                }
+            }
+        }
+        $(
+            quick_error!(FIND_FROM_IMPL
+                $name $item: $imode [$( $var:$typ ),*]
+                {$( $funcs )*});
+        )*
+        $(
+            quick_error!(FIND_CONTEXT_IMPL
+                $name $item: $imode [$( $var:$typ ),*]
+                {$( $funcs )*});
+        )*
+    };
+    (FIND_DISPLAY_IMPL $name:ident $item:ident: $imode:tt
+        { display($self_:tt) -> ($( $exprs:tt )*) $( $tail:tt )*}
+    ) => {
+        |quick_error!(IDENT $self_): &$name, f: &mut ::std::fmt::Formatter| { write!(f, $( $exprs )*) }
+    };
+    (FIND_DISPLAY_IMPL $name:ident $item:ident: $imode:tt
+        { display($pattern:expr) $( $tail:tt )*}
+    ) => {
+        |_, f: &mut ::std::fmt::Formatter| { write!(f, $pattern) }
+    };
+    (FIND_DISPLAY_IMPL $name:ident $item:ident: $imode:tt
+        { display($pattern:expr, $( $exprs:tt )*) $( $tail:tt )*}
+    ) => {
+        |_, f: &mut ::std::fmt::Formatter| { write!(f, $pattern, $( $exprs )*) }
+    };
+    (FIND_DISPLAY_IMPL $name:ident $item:ident: $imode:tt
+        { $t:tt $( $tail:tt )*}
+    ) => {
+        quick_error!(FIND_DISPLAY_IMPL
+            $name $item: $imode
+            {$( $tail )*})
+    };
+    (FIND_DISPLAY_IMPL $name:ident $item:ident: $imode:tt
+        { }
+    ) => {
+        |self_: &$name, f: &mut ::std::fmt::Formatter| {
+            write!(f, "{}", ::std::error::Error::description(self_))
+        }
+    };
+    (FIND_DESCRIPTION_IMPL $item:ident: $imode:tt $me:ident $fmt:ident
+        [$( $var:ident ),*]
+        { description($expr:expr) $( $tail:tt )*}
+    ) => {
+        $expr
+    };
+    (FIND_DESCRIPTION_IMPL $item:ident: $imode:tt $me:ident $fmt:ident
+        [$( $var:ident ),*]
+        { $t:tt $( $tail:tt )*}
+    ) => {
+        quick_error!(FIND_DESCRIPTION_IMPL
+            $item: $imode $me $fmt [$( $var ),*]
+            {$( $tail )*})
+    };
+    (FIND_DESCRIPTION_IMPL $item:ident: $imode:tt $me:ident $fmt:ident
+        [$( $var:ident ),*]
+        { }
+    ) => {
+        stringify!($item)
+    };
+    (FIND_CAUSE_IMPL $item:ident: $imode:tt
+        [$( $var:ident ),*]
+        { cause($expr:expr) $( $tail:tt )*}
+    ) => {
+        Some($expr)
+    };
+    (FIND_CAUSE_IMPL $item:ident: $imode:tt
+        [$( $var:ident ),*]
+        { $t:tt $( $tail:tt )*}
+    ) => {
+        quick_error!(FIND_CAUSE_IMPL
+            $item: $imode [$( $var ),*]
+            { $($tail)* })
+    };
+    (FIND_CAUSE_IMPL $item:ident: $imode:tt
+        [$( $var:ident ),*]
+        { }
+    ) => {
+        None
+    };
+    // ----------------------------- FROM IMPL --------------------------
+    (FIND_FROM_IMPL $name:ident $item:ident: $imode:tt
+        [$( $var:ident: $typ:ty ),*]
+        { from() $( $tail:tt )*}
+    ) => {
+        $(
+            impl From<$typ> for $name {
+                fn from($var: $typ) -> $name {
+                    $name::$item($var)
+                }
+            }
+        )*
+        quick_error!(FIND_FROM_IMPL
+            $name $item: $imode [$( $var:$typ ),*]
+            {$( $tail )*});
+    };
+    (FIND_FROM_IMPL $name:ident $item:ident: UNIT
+        [ ]
+        { from($ftyp:ty) $( $tail:tt )*}
+    ) => {
+        impl From<$ftyp> for $name {
+            fn from(_discarded_error: $ftyp) -> $name {
+                $name::$item
+            }
+        }
+        quick_error!(FIND_FROM_IMPL
+            $name $item: UNIT [  ]
+            {$( $tail )*});
+    };
+    (FIND_FROM_IMPL $name:ident $item:ident: TUPLE
+        [$( $var:ident: $typ:ty ),*]
+        { from($fvar:ident: $ftyp:ty) -> ($( $texpr:expr ),*) $( $tail:tt )*}
+    ) => {
+        impl From<$ftyp> for $name {
+            fn from($fvar: $ftyp) -> $name {
+                $name::$item($( $texpr ),*)
+            }
+        }
+        quick_error!(FIND_FROM_IMPL
+            $name $item: TUPLE [$( $var:$typ ),*]
+            { $($tail)* });
+    };
+    (FIND_FROM_IMPL $name:ident $item:ident: STRUCT
+        [$( $var:ident: $typ:ty ),*]
+        { from($fvar:ident: $ftyp:ty) -> {$( $tvar:ident: $texpr:expr ),*} $( $tail:tt )*}
+    ) => {
+        impl From<$ftyp> for $name {
+            fn from($fvar: $ftyp) -> $name {
+                $name::$item {
+                    $( $tvar: $texpr ),*
+                }
+            }
+        }
+        quick_error!(FIND_FROM_IMPL
+            $name $item: STRUCT [$( $var:$typ ),*]
+            { $($tail)* });
+    };
+    (FIND_FROM_IMPL $name:ident $item:ident: $imode:tt
+        [$( $var:ident: $typ:ty ),*]
+        { $t:tt $( $tail:tt )*}
+    ) => {
+        quick_error!(FIND_FROM_IMPL
+            $name $item: $imode [$( $var:$typ ),*]
+            {$( $tail )*}
+        );
+    };
+    (FIND_FROM_IMPL $name:ident $item:ident: $imode:tt
+        [$( $var:ident: $typ:ty ),*]
+        { }
+    ) => {
+    };
+    // ----------------------------- CONTEXT IMPL --------------------------
+    (FIND_CONTEXT_IMPL $name:ident $item:ident: TUPLE
+        [$( $var:ident: $typ:ty ),*]
+        { context($cvar:ident: AsRef<$ctyp:ty>, $fvar:ident: $ftyp:ty)
+            -> ($( $texpr:expr ),*) $( $tail:tt )* }
+    ) => {
+        impl<T: AsRef<$ctyp>> From<$crate::Context<T, $ftyp>> for $name {
+            fn from(
+                $crate::Context($cvar, $fvar): $crate::Context<T, $ftyp>)
+                -> $name
+            {
+                $name::$item($( $texpr ),*)
+            }
+        }
+        quick_error!(FIND_CONTEXT_IMPL
+            $name $item: TUPLE [$( $var:$typ ),*]
+            { $($tail)* });
+    };
+    (FIND_CONTEXT_IMPL $name:ident $item:ident: TUPLE
+        [$( $var:ident: $typ:ty ),*]
+        { context($cvar:ident: $ctyp:ty, $fvar:ident: $ftyp:ty)
+            -> ($( $texpr:expr ),*) $( $tail:tt )* }
+    ) => {
+        impl<'a> From<$crate::Context<$ctyp, $ftyp>> for $name {
+            fn from(
+                $crate::Context($cvar, $fvar): $crate::Context<$ctyp, $ftyp>)
+                -> $name
+            {
+                $name::$item($( $texpr ),*)
+            }
+        }
+        quick_error!(FIND_CONTEXT_IMPL
+            $name $item: TUPLE [$( $var:$typ ),*]
+            { $($tail)* });
+    };
+    (FIND_CONTEXT_IMPL $name:ident $item:ident: STRUCT
+        [$( $var:ident: $typ:ty ),*]
+        { context($cvar:ident: AsRef<$ctyp:ty>, $fvar:ident: $ftyp:ty)
+            -> {$( $tvar:ident: $texpr:expr ),*} $( $tail:tt )* }
+    ) => {
+        impl<T: AsRef<$ctyp>> From<$crate::Context<T, $ftyp>> for $name {
+            fn from(
+                $crate::Context($cvar, $fvar): $crate::Context<$ctyp, $ftyp>)
+                -> $name
+            {
+                $name::$item {
+                    $( $tvar: $texpr ),*
+                }
+            }
+        }
+        quick_error!(FIND_CONTEXT_IMPL
+            $name $item: STRUCT [$( $var:$typ ),*]
+            { $($tail)* });
+    };
+    (FIND_CONTEXT_IMPL $name:ident $item:ident: STRUCT
+        [$( $var:ident: $typ:ty ),*]
+        { context($cvar:ident: $ctyp:ty, $fvar:ident: $ftyp:ty)
+            -> {$( $tvar:ident: $texpr:expr ),*} $( $tail:tt )* }
+    ) => {
+        impl<'a> From<$crate::Context<$ctyp, $ftyp>> for $name {
+            fn from(
+                $crate::Context($cvar, $fvar): $crate::Context<$ctyp, $ftyp>)
+                -> $name
+            {
+                $name::$item {
+                    $( $tvar: $texpr ),*
+                }
+            }
+        }
+        quick_error!(FIND_CONTEXT_IMPL
+            $name $item: STRUCT [$( $var:$typ ),*]
+            { $($tail)* });
+    };
+    (FIND_CONTEXT_IMPL $name:ident $item:ident: $imode:tt
+        [$( $var:ident: $typ:ty ),*]
+        { $t:tt $( $tail:tt )*}
+    ) => {
+        quick_error!(FIND_CONTEXT_IMPL
+            $name $item: $imode [$( $var:$typ ),*]
+            {$( $tail )*}
+        );
+    };
+    (FIND_CONTEXT_IMPL $name:ident $item:ident: $imode:tt
+        [$( $var:ident: $typ:ty ),*]
+        { }
+    ) => {
+    };
+    // ----------------------------- ITEM IMPL --------------------------
+    (ITEM_BODY $(#[$imeta:meta])* $item:ident: UNIT
+    ) => { };
+    (ITEM_BODY $(#[$imeta:meta])* $item:ident: TUPLE
+        [$( $typ:ty ),*]
+    ) => {
+        ($( $typ ),*)
+    };
+    (ITEM_BODY $(#[$imeta:meta])* $item:ident: STRUCT
+        [$( $var:ident: $typ:ty ),*]
+    ) => {
+        {$( $var:$typ ),*}
+    };
+    (ITEM_PATTERN $name:ident $item:ident: UNIT []
+    ) => {
+        $name::$item
+    };
+    (ITEM_PATTERN $name:ident $item:ident: TUPLE
+        [$( ref $var:ident ),*]
+    ) => {
+        $name::$item ($( ref $var ),*)
+    };
+    (ITEM_PATTERN $name:ident $item:ident: STRUCT
+        [$( ref $var:ident ),*]
+    ) => {
+        $name::$item {$( ref $var ),*}
+    };
+    // This one should match all allowed sequences in "funcs" but not match
+    // anything else.
+    // This is to contrast FIND_* clauses which just find stuff they need and
+    // skip everything else completely
+    (ERROR_CHECK $imode:tt display($self_:tt) -> ($( $exprs:tt )*) $( $tail:tt )*)
+    => { quick_error!(ERROR_CHECK $imode $($tail)*); };
+    (ERROR_CHECK $imode:tt display($pattern: expr) $( $tail:tt )*)
+    => { quick_error!(ERROR_CHECK $imode $($tail)*); };
+    (ERROR_CHECK $imode:tt display($pattern: expr, $( $exprs:tt )*) $( $tail:tt )*)
+    => { quick_error!(ERROR_CHECK $imode $($tail)*); };
+    (ERROR_CHECK $imode:tt description($expr:expr) $( $tail:tt )*)
+    => { quick_error!(ERROR_CHECK $imode $($tail)*); };
+    (ERROR_CHECK $imode:tt cause($expr:expr) $($tail:tt)*)
+    => { quick_error!(ERROR_CHECK $imode $($tail)*); };
+    (ERROR_CHECK $imode:tt from() $($tail:tt)*)
+    => { quick_error!(ERROR_CHECK $imode $($tail)*); };
+    (ERROR_CHECK $imode:tt from($ftyp:ty) $($tail:tt)*)
+    => { quick_error!(ERROR_CHECK $imode $($tail)*); };
+    (ERROR_CHECK TUPLE from($fvar:ident: $ftyp:ty) -> ($( $e:expr ),*) $( $tail:tt )*)
+    => { quick_error!(ERROR_CHECK TUPLE $($tail)*); };
+    (ERROR_CHECK STRUCT from($fvar:ident: $ftyp:ty) -> {$( $v:ident: $e:expr ),*} $( $tail:tt )*)
+    => { quick_error!(ERROR_CHECK STRUCT $($tail)*); };
+
+    (ERROR_CHECK TUPLE context($cvar:ident: $ctyp:ty, $fvar:ident: $ftyp:ty)
+        -> ($( $e:expr ),*) $( $tail:tt )*)
+    => { quick_error!(ERROR_CHECK TUPLE $($tail)*); };
+    (ERROR_CHECK STRUCT context($cvar:ident: $ctyp:ty, $fvar:ident: $ftyp:ty)
+        -> {$( $v:ident: $e:expr ),*} $( $tail:tt )*)
+    => { quick_error!(ERROR_CHECK STRUCT $($tail)*); };
+
+    (ERROR_CHECK $imode:tt ) => {};
+    // Utility functions
+    (IDENT $ident:ident) => { $ident }
+}
+
+
+/// Generic context type
+///
+/// Used mostly as a transport for `ResultExt::context` method
+#[derive(Debug)]
+pub struct Context<X, E>(pub X, pub E);
+
+/// Result extension trait adding a `context` method
+pub trait ResultExt<T, E> {
+    /// The method is use to add context information to current operation
+    ///
+    /// The context data is then used in error constructor to store additional
+    /// information within error. For example, you may add a filename as a
+    /// context for file operation. See crate documentation for the actual
+    /// example.
+    fn context<X>(self, x: X) -> Result<T, Context<X, E>>;
+}
+
+impl<T, E> ResultExt<T, E> for Result<T, E> {
+    fn context<X>(self, x: X) -> Result<T, Context<X, E>> {
+        self.map_err(|e| Context(x, e))
+    }
+}
+
+
+
+#[cfg(test)]
+mod test {
+    use std::num::{ParseFloatError, ParseIntError};
+    use std::str::Utf8Error;
+    use std::string::FromUtf8Error;
+    use std::error::Error;
+    use std::path::{Path, PathBuf};
+
+    use super::ResultExt;
+
+    quick_error! {
+        #[derive(Debug)]
+        pub enum Bare {
+            One
+            Two
+        }
+    }
+
+    #[test]
+    fn bare_item_direct() {
+        assert_eq!(format!("{}", Bare::One), "One".to_string());
+        assert_eq!(format!("{:?}", Bare::One), "One".to_string());
+        assert_eq!(Bare::One.description(), "One".to_string());
+        assert!(Bare::One.cause().is_none());
+    }
+    #[test]
+    fn bare_item_trait() {
+        let err: &Error = &Bare::Two;
+        assert_eq!(format!("{}", err), "Two".to_string());
+        assert_eq!(format!("{:?}", err), "Two".to_string());
+        assert_eq!(err.description(), "Two".to_string());
+        assert!(err.cause().is_none());
+    }
+
+    quick_error! {
+        #[derive(Debug)]
+        pub enum Wrapper wraps Wrapped {
+            One
+            Two(s: String) {
+                display("two: {}", s)
+                from()
+            }
+        }
+    }
+
+    #[test]
+    fn wrapper() {
+        assert_eq!(format!("{}", Wrapper::from(Wrapped::One)),
+            "One".to_string());
+        assert_eq!(format!("{}",
+            Wrapper::from(Wrapped::from(String::from("hello")))),
+            "two: hello".to_string());
+        assert_eq!(format!("{:?}", Wrapper::from(Wrapped::One)),
+            "Wrapper(One)".to_string());
+        assert_eq!(Wrapper::from(Wrapped::One).description(),
+            "One".to_string());
+    }
+
+    quick_error! {
+        #[derive(Debug, PartialEq)]
+        pub enum TupleWrapper {
+            /// ParseFloat Error
+            ParseFloatError(err: ParseFloatError) {
+                from()
+                description(err.description())
+                display("parse float error: {err}", err=err)
+                cause(err)
+            }
+            Other(descr: &'static str) {
+                description(descr)
+                display("Error: {}", descr)
+            }
+            /// FromUtf8 Error
+            FromUtf8Error(err: Utf8Error, source: Vec<u8>) {
+                cause(err)
+                display(me) -> ("{desc} at index {pos}: {err}", desc=me.description(), pos=err.valid_up_to(), err=err)
+                description("utf8 error")
+                from(err: FromUtf8Error) -> (err.utf8_error().clone(), err.into_bytes())
+            }
+            Discard {
+                from(&'static str)
+            }
+            Singleton {
+                display("Just a string")
+            }
+        }
+    }
+
+    #[test]
+    fn tuple_wrapper_err() {
+        let cause = "one and a half times pi".parse::<f32>().unwrap_err();
+        let err = TupleWrapper::ParseFloatError(cause.clone());
+        assert_eq!(format!("{}", err), format!("parse float error: {}", cause));
+        assert_eq!(format!("{:?}", err), format!("ParseFloatError({:?})", cause));
+        assert_eq!(err.description(), cause.description());
+        assert_eq!(format!("{:?}", err.cause().unwrap()), format!("{:?}", cause));
+    }
+
+    #[test]
+    fn tuple_wrapper_trait_str() {
+        let desc = "hello";
+        let err: &Error = &TupleWrapper::Other(desc);
+        assert_eq!(format!("{}", err), format!("Error: {}", desc));
+        assert_eq!(format!("{:?}", err), format!("Other({:?})", desc));
+        assert_eq!(err.description(), desc);
+        assert!(err.cause().is_none());
+    }
+
+    #[test]
+    fn tuple_wrapper_trait_two_fields() {
+        let invalid_utf8: Vec<u8> = vec![0, 159, 146, 150];
+        let cause = String::from_utf8(invalid_utf8.clone()).unwrap_err().utf8_error();
+        let err: &Error = &TupleWrapper::FromUtf8Error(cause.clone(), invalid_utf8.clone());
+        assert_eq!(format!("{}", err), format!("{desc} at index {pos}: {cause}", desc=err.description(), pos=cause.valid_up_to(), cause=cause));
+        assert_eq!(format!("{:?}", err), format!("FromUtf8Error({:?}, {:?})", cause, invalid_utf8));
+        assert_eq!(err.description(), "utf8 error");
+        assert_eq!(format!("{:?}", err.cause().unwrap()), format!("{:?}", cause));
+    }
+
+    #[test]
+    fn tuple_wrapper_from() {
+        let cause = "one and a half times pi".parse::<f32>().unwrap_err();
+        let err = TupleWrapper::ParseFloatError(cause.clone());
+        let err_from: TupleWrapper = From::from(cause);
+        assert_eq!(err_from, err);
+    }
+
+    #[test]
+    fn tuple_wrapper_custom_from() {
+        let invalid_utf8: Vec<u8> = vec![0, 159, 146, 150];
+        let cause = String::from_utf8(invalid_utf8.clone()).unwrap_err();
+        let err = TupleWrapper::FromUtf8Error(cause.utf8_error().clone(), invalid_utf8);
+        let err_from: TupleWrapper = From::from(cause);
+        assert_eq!(err_from, err);
+    }
+
+    #[test]
+    fn tuple_wrapper_discard() {
+        let err: TupleWrapper = From::from("hello");
+        assert_eq!(format!("{}", err), format!("Discard"));
+        assert_eq!(format!("{:?}", err), format!("Discard"));
+        assert_eq!(err.description(), "Discard");
+        assert!(err.cause().is_none());
+    }
+
+    #[test]
+    fn tuple_wrapper_singleton() {
+        let err: TupleWrapper = TupleWrapper::Singleton;
+        assert_eq!(format!("{}", err), format!("Just a string"));
+        assert_eq!(format!("{:?}", err), format!("Singleton"));
+        assert_eq!(err.description(), "Singleton");
+        assert!(err.cause().is_none());
+    }
+
+    quick_error! {
+        #[derive(Debug, PartialEq)]
+        pub enum StructWrapper {
+            // Utf8 Error
+            Utf8Error{ err: Utf8Error, hint: Option<&'static str> } {
+                cause(err)
+                display(me) -> ("{desc} at index {pos}: {err}", desc=me.description(), pos=err.valid_up_to(), err=err)
+                description("utf8 error")
+                from(err: Utf8Error) -> { err: err, hint: None }
+            }
+            // Utf8 Error
+            ExcessComma { descr: &'static str, } {
+                description(descr)
+                display("Error: {}", descr)
+            }
+        }
+    }
+
+    #[test]
+    fn struct_wrapper_err() {
+        let invalid_utf8: Vec<u8> = vec![0, 159, 146, 150];
+        let cause = String::from_utf8(invalid_utf8.clone()).unwrap_err().utf8_error();
+        let err: &Error = &StructWrapper::Utf8Error{ err: cause.clone(), hint: Some("nonsense") };
+        assert_eq!(format!("{}", err), format!("{desc} at index {pos}: {cause}", desc=err.description(), pos=cause.valid_up_to(), cause=cause));
+        assert_eq!(format!("{:?}", err), format!("Utf8Error {{ err: {:?}, hint: {:?} }}", cause, Some("nonsense")));
+        assert_eq!(err.description(), "utf8 error");
+        assert_eq!(format!("{:?}", err.cause().unwrap()), format!("{:?}", cause));
+    }
+
+    #[test]
+    fn struct_wrapper_struct_from() {
+        let invalid_utf8: Vec<u8> = vec![0, 159, 146, 150];
+        let cause = String::from_utf8(invalid_utf8.clone()).unwrap_err().utf8_error();
+        let err = StructWrapper::Utf8Error{ err: cause.clone(), hint: None };
+        let err_from: StructWrapper = From::from(cause);
+        assert_eq!(err_from, err);
+    }
+
+    #[test]
+    fn struct_wrapper_excess_comma() {
+        let descr = "hello";
+        let err = StructWrapper::ExcessComma { descr: descr };
+        assert_eq!(format!("{}", err), format!("Error: {}", descr));
+        assert_eq!(format!("{:?}", err), format!("ExcessComma {{ descr: {:?} }}", descr));
+        assert_eq!(err.description(), descr);
+        assert!(err.cause().is_none());
+    }
+
+    quick_error! {
+        #[derive(Debug)]
+        pub enum ContextErr {
+            Float(src: String, err: ParseFloatError) {
+                context(s: &'a str, e: ParseFloatError) -> (s.to_string(), e)
+                display("Float error {:?}: {}", src, err)
+            }
+            Int { src: String, err: ParseIntError } {
+                context(s: &'a str, e: ParseIntError)
+                    -> {src: s.to_string(), err: e}
+                display("Int error {:?}: {}", src, err)
+            }
+            Utf8(path: PathBuf, err: Utf8Error) {
+                context(p: AsRef<Path>, e: Utf8Error)
+                    -> (p.as_ref().to_path_buf(), e)
+                display("Path error at {:?}: {}", path, err)
+            }
+            Utf8Str(s: String, err: ::std::io::Error) {
+                context(s: AsRef<str>, e: ::std::io::Error)
+                    -> (s.as_ref().to_string(), e)
+                display("Str error {:?}: {}", s, err)
+            }
+        }
+    }
+
+    #[test]
+    fn parse_float_error() {
+        fn parse_float(s: &str) -> Result<f32, ContextErr> {
+            Ok(try!(s.parse().context(s)))
+        }
+        assert_eq!(format!("{}", parse_float("12ab").unwrap_err()),
+            r#"Float error "12ab": invalid float literal"#);
+    }
+
+    #[test]
+    fn parse_int_error() {
+        fn parse_int(s: &str) -> Result<i32, ContextErr> {
+            Ok(try!(s.parse().context(s)))
+        }
+        assert_eq!(format!("{}", parse_int("12.5").unwrap_err()),
+            r#"Int error "12.5": invalid digit found in string"#);
+    }
+
+    #[test]
+    fn debug_context() {
+        fn parse_int(s: &str) -> i32 {
+            s.parse().context(s).unwrap()
+        }
+        assert_eq!(parse_int("12"), 12);
+        assert_eq!(format!("{:?}", "x".parse::<i32>().context("x")),
+            r#"Err(Context("x", ParseIntError { kind: InvalidDigit }))"#);
+    }
+
+    #[test]
+    fn path_context() {
+        fn parse_utf<P: AsRef<Path>>(s: &[u8], p: P)
+            -> Result<(), ContextErr>
+        {
+            try!(::std::str::from_utf8(s).context(p));
+            Ok(())
+        }
+        let etext = parse_utf(b"a\x80\x80", "/etc").unwrap_err().to_string();
+        assert!(etext.starts_with(
+            "Path error at \"/etc\": invalid utf-8"));
+        let etext = parse_utf(b"\x80\x80", PathBuf::from("/tmp")).unwrap_err()
+            .to_string();
+        assert!(etext.starts_with(
+            "Path error at \"/tmp\": invalid utf-8"));
+    }
+
+    #[test]
+    fn conditional_compilation() {
+        quick_error! {
+            #[allow(dead_code)]
+            #[derive(Debug)]
+            pub enum Test {
+                #[cfg(feature = "foo")]
+                Variant
+            }
+        }
+    }
+}
diff --git a/vagga.yaml b/vagga.yaml
new file mode 100644 (file)
index 0000000..74d4355
--- /dev/null
@@ -0,0 +1,27 @@
+commands:
+
+  cargo: !Command
+    description: Run any cargo command
+    container: ubuntu
+    run: [cargo]
+
+  test: !Command
+    description: Run unit tests
+    container: ubuntu
+    run: [cargo, test]
+
+containers:
+
+  ubuntu:
+    setup:
+    - !Ubuntu xenial
+    - !Install [ca-certificates, build-essential]
+
+    - !TarInstall
+      url: "https://static.rust-lang.org/dist/rust-1.16.0-x86_64-unknown-linux-gnu.tar.gz"
+      script: "./install.sh --prefix=/usr \
+                --components=rustc,rust-std-x86_64-unknown-linux-gnu,cargo"
+
+    environ:
+      HOME: /work/target
+      USER: pc