chain.rs
This file
Path
src/chain.rs
102 lines · 2.7 KiB · Rust
Last changed by
Merge pull request #383 from dtolnay/nostdDavid Tolnaybefore adoption8ecfcdf
History of this fileTake it
The walk stopped after 200 commits: lines older than 553ed38 point at it.
Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38
lines 1–3why, one step back1use self::ChainState::*;2use crate::StdError;3Merge pull request #383 from dtolnay/nostdDavid Tolnaybefore adoption8ecfcdf
line 4why, one step back4#[cfg(any(feature = "std", not(anyhow_no_core_error)))]Work around prelude redundant import warningsDavid Tolnaybefore adoptiondfc7bc0
line 5why, one step back5use alloc::vec::{self, Vec};Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38
line 6why, one step back6Merge pull request #383 from dtolnay/nostdDavid Tolnaybefore adoption8ecfcdf
line 7why, one step back7#[cfg(any(feature = "std", not(anyhow_no_core_error)))]Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38
lines 8–9why, one step back8pub(crate) use crate::Chain;9Merge pull request #383 from dtolnay/nostdDavid Tolnaybefore adoption8ecfcdf
line 10why, one step back10#[cfg(all(not(feature = "std"), anyhow_no_core_error))]Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38
lines 11–19why, one step back11pub(crate) struct Chain<'a> {12 state: ChainState<'a>,13}1415#[derive(Clone)]16pub(crate) enum ChainState<'a> {17 Linked {18 next: Option<&'a (dyn StdError + 'static)>,19 },Merge pull request #383 from dtolnay/nostdDavid Tolnaybefore adoption8ecfcdf
line 20why, one step back20 #[cfg(any(feature = "std", not(anyhow_no_core_error)))]Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38
lines 21–44why, one step back21 Buffered {22 rest: vec::IntoIter<&'a (dyn StdError + 'static)>,23 },24}2526impl<'a> Chain<'a> {27 #[cold]28 pub fn new(head: &'a (dyn StdError + 'static)) -> Self {29 Chain {30 state: ChainState::Linked { next: Some(head) },31 }32 }33}3435impl<'a> Iterator for Chain<'a> {36 type Item = &'a (dyn StdError + 'static);3738 fn next(&mut self) -> Option<Self::Item> {39 match &mut self.state {40 Linked { next } => {41 let error = (*next)?;42 *next = error.source();43 Some(error)44 }Merge pull request #383 from dtolnay/nostdDavid Tolnaybefore adoption8ecfcdf
line 45why, one step back45 #[cfg(any(feature = "std", not(anyhow_no_core_error)))]Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38
lines 46–55why, one step back46 Buffered { rest } => rest.next(),47 }48 }4950 fn size_hint(&self) -> (usize, Option<usize>) {51 let len = self.len();52 (len, Some(len))53 }54}55Merge pull request #383 from dtolnay/nostdDavid Tolnaybefore adoption8ecfcdf
line 56why, one step back56#[cfg(any(feature = "std", not(anyhow_no_core_error)))]Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38
lines 57–86why, one step back57impl DoubleEndedIterator for Chain<'_> {58 fn next_back(&mut self) -> Option<Self::Item> {59 match &mut self.state {60 Linked { mut next } => {61 let mut rest = Vec::new();62 while let Some(cause) = next {63 next = cause.source();64 rest.push(cause);65 }66 let mut rest = rest.into_iter();67 let last = rest.next_back();68 self.state = Buffered { rest };69 last70 }71 Buffered { rest } => rest.next_back(),72 }73 }74}7576impl ExactSizeIterator for Chain<'_> {77 fn len(&self) -> usize {78 match &self.state {79 Linked { mut next } => {80 let mut len = 0;81 while let Some(cause) = next {82 next = cause.source();83 len += 1;84 }85 len86 }Merge pull request #383 from dtolnay/nostdDavid Tolnaybefore adoption8ecfcdf
line 87why, one step back87 #[cfg(any(feature = "std", not(anyhow_no_core_error)))]Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38
lines 88–92why, one step back88 Buffered { rest } => rest.len(),89 }90 }91}92Merge pull request #383 from dtolnay/nostdDavid Tolnaybefore adoption8ecfcdf
line 93why, one step back93#[cfg(any(feature = "std", not(anyhow_no_core_error)))]Update clippy.toml msrv to match rust-version in Cargo.tomlDavid Tolnaybefore adoption553ed38
lines 94–102why, one step back94impl Default for Chain<'_> {95 fn default() -> Self {96 Chain {97 state: ChainState::Buffered {98 rest: Vec::new().into_iter(),99 },100 }101 }102}