Coverage Report

Created: 2025-11-16 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/thiserror-2.0.17/src/display.rs
Line
Count
Source
1
use core::fmt::Display;
2
#[cfg(feature = "std")]
3
use std::path::{self, Path, PathBuf};
4
5
#[doc(hidden)]
6
pub trait AsDisplay<'a>: Sealed {
7
    // TODO: convert to generic associated type.
8
    // https://github.com/dtolnay/thiserror/pull/253
9
    type Target: Display;
10
11
    fn as_display(&'a self) -> Self::Target;
12
}
13
14
impl<'a, T> AsDisplay<'a> for &T
15
where
16
    T: Display + ?Sized + 'a,
17
{
18
    type Target = &'a T;
19
20
0
    fn as_display(&'a self) -> Self::Target {
21
0
        *self
22
0
    }
Unexecuted instantiation: <&alloc::boxed::Box<hickory_proto::error::ProtoError> as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&alloc::boxed::Box<hickory_proto::op::query::Query> as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&hickory_proto::rr::record_type::RecordType as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&hickory_proto::dnssec::proof::Proof as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&hickory_proto::dnssec::algorithm::Algorithm as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&str as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&u8 as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&usize as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&u16 as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&hickory_proto::rr::domain::name::Name as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&hickory_proto::op::query::Query as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&hickory_proto::error::ProtoError as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&hickory_proto::error::DnsError as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&hickory_proto::serialize::binary::decoder::DecodeError as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&alloc::string::String as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&hickory_proto::op::response_code::ResponseCode as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&alloc::sync::Arc<std::io::error::Error> as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&aws_lc_rs::error::KeyRejected as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&aws_lc_rs::error::Unspecified as thiserror::display::AsDisplay>::as_display
23
}
24
25
#[cfg(feature = "std")]
26
impl<'a> AsDisplay<'a> for Path {
27
    type Target = path::Display<'a>;
28
29
    #[inline]
30
    fn as_display(&'a self) -> Self::Target {
31
        self.display()
32
    }
33
}
34
35
#[cfg(feature = "std")]
36
impl<'a> AsDisplay<'a> for PathBuf {
37
    type Target = path::Display<'a>;
38
39
    #[inline]
40
    fn as_display(&'a self) -> Self::Target {
41
        self.display()
42
    }
43
}
44
45
#[doc(hidden)]
46
pub trait Sealed {}
47
impl<T: Display + ?Sized> Sealed for &T {}
48
#[cfg(feature = "std")]
49
impl Sealed for Path {}
50
#[cfg(feature = "std")]
51
impl Sealed for PathBuf {}
52
53
// Add a synthetic second impl of AsDisplay to prevent the "single applicable
54
// impl" rule from making too weird inference decision based on the single impl
55
// for &T, which could lead to code that compiles with thiserror's std feature
56
// off but breaks under feature unification when std is turned on by an
57
// unrelated crate.
58
#[cfg(not(feature = "std"))]
59
mod placeholder {
60
    use super::{AsDisplay, Sealed};
61
    use core::fmt::{self, Display};
62
63
    #[allow(dead_code)]
64
    pub struct Placeholder;
65
66
    impl<'a> AsDisplay<'a> for Placeholder {
67
        type Target = Self;
68
69
        #[inline]
70
        fn as_display(&'a self) -> Self::Target {
71
            Placeholder
72
        }
73
    }
74
75
    impl Display for Placeholder {
76
        fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
77
            unreachable!()
78
        }
79
    }
80
81
    impl Sealed for Placeholder {}
82
}