From 52e5ec806457c2784d85dc4e4a332c07e6eea818 Mon Sep 17 00:00:00 2001 From: Paul Colomiets Date: Sat, 8 Jan 2022 03:34:39 +0200 Subject: [PATCH] fix(chain): correct `Chain` structure exported (#102) This fixes all current complier and clippy warnings. --- src/chain.rs | 21 ++++++++++++++++++++- src/eyreish/mod.rs | 25 ------------------------- tests/test_context.rs | 1 + 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/chain.rs b/src/chain.rs index fe4d336..7a66383 100644 --- a/src/chain.rs +++ b/src/chain.rs @@ -8,6 +8,25 @@ use std::vec; use ChainState::*; +/// Iterator of a chain of source errors. +/// +/// This type is the iterator returned by [`Report::chain`]. +/// +/// # Example +/// +/// ``` +/// use miette::Report; +/// use std::io; +/// +/// pub fn underlying_io_error_kind(error: &Report) -> Option { +/// for cause in error.chain() { +/// if let Some(io_error) = cause.downcast_ref::() { +/// return Some(io_error.kind()); +/// } +/// } +/// None +/// } +/// ``` #[derive(Clone)] #[allow(missing_debug_implementations)] pub struct Chain<'a> { @@ -25,7 +44,7 @@ pub(crate) enum ChainState<'a> { } impl<'a> Chain<'a> { - pub fn new(head: &'a (dyn StdError + 'static)) -> Self { + pub(crate) fn new(head: &'a (dyn StdError + 'static)) -> Self { Chain { state: ChainState::Linked { next: Some(head) }, } diff --git a/src/eyreish/mod.rs b/src/eyreish/mod.rs index 26776c5..6082356 100644 --- a/src/eyreish/mod.rs +++ b/src/eyreish/mod.rs @@ -191,31 +191,6 @@ pub trait ReportHandler: core::any::Any + Send + Sync { fn track_caller(&mut self, location: &'static std::panic::Location<'static>) {} } -/// Iterator of a chain of source errors. -/// -/// This type is the iterator returned by [`Report::chain`]. -/// -/// # Example -/// -/// ``` -/// use miette::Report; -/// use std::io; -/// -/// pub fn underlying_io_error_kind(error: &Report) -> Option { -/// for cause in error.chain() { -/// if let Some(io_error) = cause.downcast_ref::() { -/// return Some(io_error.kind()); -/// } -/// } -/// None -/// } -/// ``` -#[derive(Clone)] -#[allow(missing_debug_implementations)] -pub struct Chain<'a> { - state: crate::chain::ChainState<'a>, -} - /// type alias for `Result` /// /// This is a reasonable return type to use throughout your application but also for `fn main`; if diff --git a/tests/test_context.rs b/tests/test_context.rs index 5f78572..9788f50 100644 --- a/tests/test_context.rs +++ b/tests/test_context.rs @@ -19,6 +19,7 @@ macro_rules! context_type { #[derive(Debug)] struct $name { message: &'static str, + #[allow(dead_code)] drop: DetectDrop, }