Skip to content

Commit 6a92e8b

Browse files
committed
Merge #278: Crate docs for located-error package
117dc0b docs: [#275] crate docs for locate-error package (Jose Celano) Pull request description: Documentation for the `located-error` package (`./package/located-error`). Top commit has no ACKs. Tree-SHA512: 9a4ecdf7e009df3c0ffbbd583e94038f87aea967485a5efb1fae590fff22566793ef79d6c13cc013a77029db9ebb99fb59562600fd86c75a2d70b25dda7c4a3b
2 parents 52297fa + 117dc0b commit 6a92e8b

File tree

1 file changed

+36
-3
lines changed
  • packages/located-error/src

1 file changed

+36
-3
lines changed

packages/located-error/src/lib.rs

+36-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
1-
// https://stackoverflow.com/questions/74336993/getting-line-numbers-with-when-using-boxdyn-stderrorerror
2-
1+
//! This crate provides a wrapper around an error that includes the location of
2+
//! the error.
3+
//!
4+
//! ```rust
5+
//! use std::error::Error;
6+
//! use std::panic::Location;
7+
//! use std::sync::Arc;
8+
//! use torrust_tracker_located_error::{Located, LocatedError};
9+
//!
10+
//! #[derive(thiserror::Error, Debug)]
11+
//! enum TestError {
12+
//! #[error("Test")]
13+
//! Test,
14+
//! }
15+
//!
16+
//! #[track_caller]
17+
//! fn get_caller_location() -> Location<'static> {
18+
//! *Location::caller()
19+
//! }
20+
//!
21+
//! let e = TestError::Test;
22+
//!
23+
//! let b: LocatedError<TestError> = Located(e).into();
24+
//! let l = get_caller_location();
25+
//!
26+
//! assert!(b.to_string().contains("Test, src/lib.rs"));
27+
//! ```
28+
//!
29+
//! # Credits
30+
//!
31+
//! <https://stackoverflow.com/questions/74336993/getting-line-numbers-with-when-using-boxdyn-stderrorerror>
332
use std::error::Error;
433
use std::panic::Location;
534
use std::sync::Arc;
635

36+
/// A generic wrapper around an error.
37+
///
38+
/// Where `E` is the inner error (source error).
739
pub struct Located<E>(pub E);
840

41+
/// A wrapper around an error that includes the location of the error.
942
#[derive(Debug)]
1043
pub struct LocatedError<'a, E>
1144
where
@@ -78,7 +111,7 @@ mod tests {
78111
use std::panic::Location;
79112

80113
use super::LocatedError;
81-
use crate::located_error::Located;
114+
use crate::Located;
82115

83116
#[derive(thiserror::Error, Debug)]
84117
enum TestError {

0 commit comments

Comments
 (0)