Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit 55ba205

Browse files
ehussYamakaky
authored andcommitted
Add missing hyperlinks. (#203)
Fixes #173
1 parent 9cc1c34 commit 55ba205

File tree

1 file changed

+80
-55
lines changed

1 file changed

+80
-55
lines changed

src/lib.rs

Lines changed: 80 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
//! * error-chain is easy to configure. Handle errors robustly with minimal
2525
//! effort.
2626
//! * Basic error handling requires no maintenance of custom error types
27-
//! nor the `From` conversions that make `?` work.
27+
//! nor the [`From`] conversions that make `?` work.
2828
//! * error-chain scales from simple error handling strategies to more
2929
//! rigorous. Return formatted strings for simple errors, only
3030
//! introducing error variants and their strong typing as needed for
@@ -40,56 +40,56 @@
4040
//! error-chain is based on the following principles:
4141
//!
4242
//! * No error should ever be discarded. This library primarily
43-
//! makes it easy to "chain" errors with the `chain_err` method.
43+
//! makes it easy to "chain" errors with the [`chain_err`] method.
4444
//! * Introducing new errors is trivial. Simple errors can be introduced
4545
//! at the error site with just a string.
4646
//! * Handling errors is possible with pattern matching.
4747
//! * Conversions between error types are done in an automatic and
48-
//! consistent way - `From` conversion behavior is never specified
48+
//! consistent way - [`From`] conversion behavior is never specified
4949
//! explicitly.
50-
//! * Errors implement Send.
50+
//! * Errors implement [`Send`].
5151
//! * Errors can carry backtraces.
5252
//!
5353
//! Similar to other libraries like [error-type] and [quick-error],
5454
//! this library introduces the error chaining mechanism originally
55-
//! employed by Cargo. The `error_chain!` macro declares the types
55+
//! employed by Cargo. The [`error_chain!`] macro declares the types
5656
//! and implementation boilerplate necessary for fulfilling a
5757
//! particular error-handling strategy. Most importantly it defines a
58-
//! custom error type (called `Error` by convention) and the `From`
58+
//! custom error type (called [`Error`] by convention) and the [`From`]
5959
//! conversions that let the `?` operator work.
6060
//!
6161
//! This library differs in a few ways from previous error libs:
6262
//!
63-
//! * Instead of defining the custom `Error` type as an enum, it is a
64-
//! struct containing an `ErrorKind` (which defines the
65-
//! `description` and `display_chain` methods for the error), an opaque,
66-
//! optional, boxed `std::error::Error + Send + 'static` object
67-
//! (which defines the `cause`, and establishes the links in the
68-
//! error chain), and a `Backtrace`.
69-
//! * The macro also defines a `ResultExt` trait that defines a
70-
//! `chain_err` method. This method on all `std::error::Error + Send + 'static`
63+
//! * Instead of defining the custom [`Error`] type as an enum, it is a
64+
//! struct containing an [`ErrorKind`][] (which defines the
65+
//! [`description`] and [`display_chain`] methods for the error), an opaque,
66+
//! optional, boxed [`std::error::Error`]` + `[`Send`]` + 'static` object
67+
//! (which defines the [`cause`], and establishes the links in the
68+
//! error chain), and a [`Backtrace`].
69+
//! * The macro also defines a [`ResultExt`] trait that defines a
70+
//! [`chain_err`] method. This method on all [`std::error::Error`]` + `[`Send`]` + 'static`
7171
//! types extends the error chain by boxing the current
7272
//! error into an opaque object and putting it inside a new concrete
7373
//! error.
74-
//! * It provides automatic `From` conversions between other error types
75-
//! defined by the `error_chain!` that preserve type information,
74+
//! * It provides automatic [`From`] conversions between other error types
75+
//! defined by the [`error_chain!`] that preserve type information,
7676
//! and facilitate seamless error composition and matching of composed
7777
//! errors.
78-
//! * It provides automatic `From` conversions between any other error
79-
//! type that hides the type of the other error in the `cause` box.
78+
//! * It provides automatic [`From`] conversions between any other error
79+
//! type that hides the type of the other error in the [`cause`] box.
8080
//! * If `RUST_BACKTRACE` is enabled, it collects a single backtrace at
8181
//! the earliest opportunity and propagates it down the stack through
82-
//! `From` and `ResultExt` conversions.
82+
//! [`From`] and [`ResultExt`] conversions.
8383
//!
8484
//! To accomplish its goals it makes some tradeoffs:
8585
//!
86-
//! * The split between the `Error` and `ErrorKind` types can make it
86+
//! * The split between the [`Error`] and [`ErrorKind`] types can make it
8787
//! slightly more cumbersome to instantiate new (unchained) errors,
88-
//! requiring an `Into` or `From` conversion; as well as slightly
88+
//! requiring an [`Into`] or [`From`] conversion; as well as slightly
8989
//! more cumbersome to match on errors with another layer of types
9090
//! to match.
91-
//! * Because the error type contains `std::error::Error + Send + 'static` objects,
92-
//! it can't implement `PartialEq` for easy comparisons.
91+
//! * Because the error type contains [`std::error::Error`]` + `[`Send`]` + 'static` objects,
92+
//! it can't implement [`PartialEq`] for easy comparisons.
9393
//!
9494
//! ## Declaring error types
9595
//!
@@ -98,7 +98,7 @@
9898
//! basis, such as per module.
9999
//!
100100
//! Assuming you are using crate-level error types, typically you will
101-
//! define an `errors` module and inside it call `error_chain!`:
101+
//! define an `errors` module and inside it call [`error_chain!`]:
102102
//!
103103
//! ```
104104
//! # #[macro_use] extern crate error_chain;
@@ -174,8 +174,8 @@
174174
//! be omitted if it is empty.
175175
//!
176176
//! This populates the module with a number of definitions,
177-
//! the most important of which are the `Error` type
178-
//! and the `ErrorKind` type. An example of generated code can be found in the
177+
//! the most important of which are the [`Error`] type
178+
//! and the [`ErrorKind`] type. An example of generated code can be found in the
179179
//! [example_generated](example_generated/index.html) module.
180180
//!
181181
//! ## Returning new errors
@@ -191,7 +191,7 @@
191191
//! }
192192
//! ```
193193
//!
194-
//! Introducing new error chains, with an `ErrorKind`:
194+
//! Introducing new error chains, with an [`ErrorKind`]:
195195
//!
196196
//! ```
197197
//! # #[macro_use] extern crate error_chain;
@@ -205,12 +205,12 @@
205205
//! }
206206
//! ```
207207
//!
208-
//! Note that the return type is the typedef `Result`, which is
208+
//! Note that the return type is the typedef [`Result`], which is
209209
//! defined by the macro as `pub type Result<T> =
210210
//! ::std::result::Result<T, Error>`. Note that in both cases
211-
//! `.into()` is called to convert a type into the `Error` type; both
212-
//! strings and `ErrorKind` have `From` conversions to turn them into
213-
//! `Error`.
211+
//! [`.into()`] is called to convert a type into the [`Error`] type; both
212+
//! strings and [`ErrorKind`] have [`From`] conversions to turn them into
213+
//! [`Error`].
214214
//!
215215
//! When the error is emitted behind the `?` operator, the explicit conversion
216216
//! isn't needed; `Err(ErrorKind)` will automatically be converted to `Err(Error)`.
@@ -232,10 +232,10 @@
232232
//! ## The `bail!` macro
233233
//!
234234
//! The above method of introducing new errors works but is a little
235-
//! verbose. Instead, we can use the `bail!` macro, which performs an early return
235+
//! verbose. Instead, we can use the [`bail!`] macro, which performs an early return
236236
//! with conversions done automatically.
237237
//!
238-
//! With `bail!` the previous examples look like:
238+
//! With [`bail!`] the previous examples look like:
239239
//!
240240
//! ```
241241
//! # #[macro_use] extern crate error_chain;
@@ -275,20 +275,20 @@
275275
//! # }
276276
//! ```
277277
//!
278-
//! `chain_err` can be called on any `Result` type where the contained
279-
//! error type implements `std::error::Error + Send + 'static`, as long as
280-
//! the `Result` type's corresponding `ResultExt` trait is in scope. If
281-
//! the `Result` is an `Err` then `chain_err` evaluates the closure,
282-
//! which returns *some type that can be converted to `ErrorKind`*,
278+
//! [`chain_err`] can be called on any [`Result`] type where the contained
279+
//! error type implements [`std::error::Error`]` + `[`Send`]` + 'static`, as long as
280+
//! the [`Result`] type's corresponding [`ResultExt`] trait is in scope. If
281+
//! the [`Result`] is an `Err` then [`chain_err`] evaluates the closure,
282+
//! which returns *some type that can be converted to [`ErrorKind`]*,
283283
//! boxes the original error to store as the cause, then returns a new
284284
//! error containing the original error.
285285
//!
286-
//! Calling `chain_err` on an existing `Error` instance has the same
287-
//! signature and produces the same outcome as being called on a `Result`
288-
//! matching the properties described above. This is most useful when
289-
//! partially handling errors using the `map_err` function.
286+
//! Calling [`chain_err`][Error_chain_err] on an existing [`Error`] instance has
287+
//! the same signature and produces the same outcome as being called on a
288+
//! [`Result`] matching the properties described above. This is most useful when
289+
//! partially handling errors using the [`map_err`] function.
290290
//!
291-
//! To chain an error directly, use `with_chain`:
291+
//! To chain an error directly, use [`with_chain`]:
292292
//!
293293
//! ```
294294
//! # #[macro_use] extern crate error_chain;
@@ -324,14 +324,14 @@
324324
//! # }
325325
//! ```
326326
//!
327-
//! The `Error` and `ErrorKind` types implements `From` for the corresponding
327+
//! The [`Error`] and [`ErrorKind`] types implements [`From`] for the corresponding
328328
//! types of all linked error chains. Linked errors do not introduce a new
329329
//! cause to the error chain.
330330
//!
331331
//! ## Matching errors
332332
//!
333333
//! error-chain error variants are matched with simple patterns.
334-
//! `Error` is a tuple struct and its first field is the `ErrorKind`,
334+
//! [`Error`] is a tuple struct and its first field is the [`ErrorKind`],
335335
//! making dispatching on error kinds relatively compact:
336336
//!
337337
//! ```
@@ -429,23 +429,23 @@
429429
//! # }
430430
//! ```
431431
//!
432-
//! The `Error` and `ErrorKind` types also allow programmatic access to these elements.
432+
//! The [`Error`] and [`ErrorKind`] types also allow programmatic access to these elements.
433433
//!
434434
//! ## Foreign links
435435
//!
436436
//! Errors that do not conform to the same conventions as this library
437437
//! can still be included in the error chain. They are considered "foreign
438438
//! errors", and are declared using the `foreign_links` block of the
439-
//! `error_chain!` macro. `Error`s are automatically created from
439+
//! [`error_chain!`] macro. [`Error`]s are automatically created from
440440
//! foreign errors by the `?` operator.
441441
//!
442442
//! Foreign links and regular links have one crucial difference:
443-
//! `From` conversions for regular links *do not introduce a new error
443+
//! [`From`] conversions for regular links *do not introduce a new error
444444
//! into the error chain*, while conversions for foreign links *always
445445
//! introduce a new error into the error chain*. So for the example
446-
//! above all errors deriving from the `std::fmt::Error` type will be
447-
//! presented to the user as a new `ErrorKind::Fmt` variant, and the
448-
//! cause will be the original `std::fmt::Error` error. In contrast, when
446+
//! above all errors deriving from the [`std::fmt::Error`] type will be
447+
//! presented to the user as a new [`ErrorKind`] variant, and the
448+
//! cause will be the original [`std::fmt::Error`] error. In contrast, when
449449
//! `other_error::Error` is converted to `Error` the two `ErrorKind`s
450450
//! are converted between each other to create a new `Error` but the
451451
//! old error is discarded; there is no "cause" created from the
@@ -455,19 +455,44 @@
455455
//!
456456
//! If the `RUST_BACKTRACE` environment variable is set to anything
457457
//! but ``0``, the earliest non-foreign error to be generated creates
458-
//! a single backtrace, which is passed through all `From` conversions
459-
//! and `chain_err` invocations of compatible types. To read the
460-
//! backtrace just call the `backtrace()` method.
458+
//! a single backtrace, which is passed through all [`From`] conversions
459+
//! and [`chain_err`] invocations of compatible types. To read the
460+
//! backtrace just call the [`backtrace`] method.
461461
//!
462462
//! Backtrace generation can be disabled by turning off the `backtrace` feature.
463463
//!
464464
//! ## Iteration
465465
//!
466-
//! The `iter` method returns an iterator over the chain of error boxes.
466+
//! The [`iter`] method returns an iterator over the chain of error boxes.
467467
//!
468468
//! [error-type]: https://github.com/DanielKeep/rust-error-type
469469
//! [quick-error]: https://github.com/tailhook/quick-error
470470
471+
//! [`display_chain`]: trait.ChainedError.html#method.display_chain
472+
//! [`error_chain!`]: macro.error_chain.html
473+
//! [`bail!`]: macro.bail.html
474+
//! [`Backtrace`]: struct.Backtrace.html
475+
476+
//! [`Error`]: example_generated/struct.Error.html
477+
//! [`with_chain`]: example_generated/struct.Error.html#method.with_chain
478+
//! [Error_chain_err]: example_generated/struct.Error.html#method.chain_err
479+
//! [`cause`]: example_generated/struct.Error.html#method.cause
480+
//! [`backtrace`]: example_generated/struct.Error.html#method.backtrace
481+
//! [`iter`]: example_generated/struct.Error.html#method.iter
482+
//! [`ErrorKind`]: example_generated/enum.ErrorKind.html
483+
//! [`description`]: example_generated/enum.ErrorKind.html#method.description
484+
//! [`Result`]: example_generated/type.Result.html
485+
//! [`ResultExt`]: example_generated/trait.ResultExt.html
486+
//! [`chain_err`]: example_generated/trait.ResultExt.html#tymethod.chain_err
487+
488+
//! [`std::error::Error`]: https://doc.rust-lang.org/std/error/trait.Error.html
489+
//! [`Send`]: https://doc.rust-lang.org/std/marker/trait.Send.html
490+
//! [`Into`]: https://doc.rust-lang.org/std/convert/trait.Into.html
491+
//! [`From`]: https://doc.rust-lang.org/std/convert/trait.From.html
492+
//! [`PartialEq`]: https://doc.rust-lang.org/std/cmp/trait.PartialEq.html
493+
//! [`std::fmt::Error`]: https://doc.rust-lang.org/std/fmt/struct.Error.html
494+
//! [`.into()`]: https://doc.rust-lang.org/std/convert/trait.Into.html#tymethod.into
495+
//! [`map_err`]: https://doc.rust-lang.org/std/result/enum.Result.html#method.map_err
471496
472497
#[cfg(feature = "backtrace")]
473498
extern crate backtrace;

0 commit comments

Comments
 (0)