|
461 | 461 | //!
|
462 | 462 | //! Backtrace generation can be disabled by turning off the `backtrace` feature.
|
463 | 463 | //!
|
| 464 | +//! The Backtrace contains a Vec of [`BacktraceFrame`]s that can be operated |
| 465 | +//! on directly. For example, to only see the files and line numbers of code |
| 466 | +//! within your own project. |
| 467 | +//! |
| 468 | +//! ``` |
| 469 | +//! # #[macro_use] |
| 470 | +//! # extern crate error_chain; |
| 471 | +//! # mod errors { |
| 472 | +//! # error_chain! { |
| 473 | +//! # foreign_links { |
| 474 | +//! # Io(::std::io::Error); |
| 475 | +//! # } |
| 476 | +//! # } |
| 477 | +//! # } |
| 478 | +//! # use errors::*; |
| 479 | +//! # #[cfg(feature="backtrace")] |
| 480 | +//! # fn main() { |
| 481 | +//! if let Err(ref e) = open_file() { |
| 482 | +//! if let Some(backtrace) = e.backtrace() { |
| 483 | +//! let frames = backtrace.frames(); |
| 484 | +//! for frame in frames.iter() { |
| 485 | +//! for symbol in frame.symbols().iter() { |
| 486 | +//! if let (Some(file), Some(lineno)) = (symbol.filename(), symbol.lineno()) { |
| 487 | +//! if file.display().to_string()[0..3] == "src".to_string(){ |
| 488 | +//! println!("{}:{}", file.display().to_string(), lineno); |
| 489 | +//! } |
| 490 | +//! } |
| 491 | +//! } |
| 492 | +//! } |
| 493 | +//! } |
| 494 | +//! }; |
| 495 | +//! # } |
| 496 | +//! # #[cfg(not(feature="backtrace"))] |
| 497 | +//! # fn main() { } |
| 498 | +//! |
| 499 | +//! fn open_file() -> Result<()> { |
| 500 | +//! std::fs::File::open("does_not_exist")?; |
| 501 | +//! Ok(()) |
| 502 | +//! } |
| 503 | +//! ``` |
| 504 | +//! |
464 | 505 | //! ## Iteration
|
465 | 506 | //!
|
466 | 507 | //! The [`iter`] method returns an iterator over the chain of error boxes.
|
|
493 | 534 | //! [`std::fmt::Error`]: https://doc.rust-lang.org/std/fmt/struct.Error.html
|
494 | 535 | //! [`.into()`]: https://doc.rust-lang.org/std/convert/trait.Into.html#tymethod.into
|
495 | 536 | //! [`map_err`]: https://doc.rust-lang.org/std/result/enum.Result.html#method.map_err
|
| 537 | +//! [`BacktraceFrame`]: https://docs.rs/backtrace/0.3.2/backtrace/struct.BacktraceFrame.html |
| 538 | +
|
496 | 539 |
|
497 | 540 | #[cfg(feature = "backtrace")]
|
498 | 541 | extern crate backtrace;
|
|
0 commit comments