diff --git a/color-eyre/examples/custom_filter.rs b/color-eyre/examples/custom_filter.rs index 5776d38..5da8c82 100644 --- a/color-eyre/examples/custom_filter.rs +++ b/color-eyre/examples/custom_filter.rs @@ -9,18 +9,14 @@ fn main() -> Result<(), Report> { color_eyre::config::HookBuilder::default() .add_frame_filter(Box::new(|frames| { - let filters = &["custom_filter::main"]; + let filters = ["custom_filter::main"]; frames.retain(|frame| { - !filters.iter().any(|f| { - let name = if let Some(name) = frame.name.as_ref() { - name.as_str() - } else { - return true; - }; - - name.starts_with(f) - }) + let Some(name) = frame.name.as_deref() else { + return true; + }; + + !filters.iter().any(|f| name.starts_with(f)) }); })) .install() diff --git a/color-eyre/src/config.rs b/color-eyre/src/config.rs index f8f19b4..9b1148e 100644 --- a/color-eyre/src/config.rs +++ b/color-eyre/src/config.rs @@ -641,20 +641,16 @@ impl HookBuilder { /// ```rust /// color_eyre::config::HookBuilder::default() /// .add_frame_filter(Box::new(|frames| { - /// let filters = &[ + /// let filters = [ /// "uninteresting_function", /// ]; /// /// frames.retain(|frame| { - /// !filters.iter().any(|f| { - /// let name = if let Some(name) = frame.name.as_ref() { - /// name.as_str() - /// } else { - /// return true; - /// }; + /// let Some(name) = frame.name.as_deref() else { + /// return true; + /// }; /// - /// name.starts_with(f) - /// }) + /// !filters.iter().any(|f| name.starts_with(f)) /// }); /// })) /// .install() @@ -768,22 +764,18 @@ fn default_frame_filter(frames: &mut Vec<&Frame>) { } fn eyre_frame_filters(frames: &mut Vec<&Frame>) { - let filters = &[ + let filters = [ "::default", "eyre::", "color_eyre::", ]; frames.retain(|frame| { - !filters.iter().any(|f| { - let name = if let Some(name) = frame.name.as_ref() { - name.as_str() - } else { - return true; - }; + let Some(name) = frame.name.as_deref() else { + return true; + }; - name.starts_with(f) - }) + !filters.iter().any(|filter| name.starts_with(filter)) }); }