Coverage Report

Created: 2025-02-25 06:39

/rust/registry/src/index.crates.io-6f17d22bba15001f/thiserror-2.0.11/src/display.rs
Line
Count
Source (jump to first uncovered line)
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: <&ipnet::ipnet::PrefixLenError as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&core::net::parser::AddrParseError as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&ztunnel::identity::Error as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&rustls::error::Error as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&core::net::ip_addr::IpAddr as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&ztunnel::proxy::AuthorizationRejectionError as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&ztunnel::proxy::Error as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&rustls_pki_types::server_name::InvalidDnsNameError as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&nom::internal::Err<x509_parser::error::X509Error> as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&rustls::webpki::VerifierBuilderError as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&core::str::error::Utf8Error as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&ztunnel::tls::Error as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&hickory_proto::error::ProtoError as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&tracing_subscriber::reload::Error as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&ztunnel::tls::lib::TlsError as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&h2::error::Error as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&core::net::socket_addr::SocketAddr as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&ztunnel::identity::manager::Identity as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&prost::error::DecodeError as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&prost::error::EncodeError as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&prost::error::UnknownEnumValue as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&alloc::boxed::Box<dyn core::error::Error + core::marker::Sync + core::marker::Send> as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&alloc::boxed::Box<ztunnel::proxy::Error> as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&alloc::boxed::Box<ztunnel::state::workload::Workload> as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&alloc::sync::Arc<ztunnel::tls::Error> as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&alloc::sync::Arc<ztunnel::state::WorkloadInfo> as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&alloc::sync::Arc<http::uri::InvalidUri> as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&hickory_server::authority::error::LookupError as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&x509_parser::error::X509Error as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&http::status::StatusCode as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&tracing_subscriber::filter::directive::ParseError as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&usize as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&anyhow::Error as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&alloc::string::String as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&asn1_rs::error::Error as thiserror::display::AsDisplay>::as_display
Unexecuted instantiation: <&std::io::error::Error 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
    pub struct Placeholder;
64
65
    impl<'a> AsDisplay<'a> for Placeholder {
66
        type Target = Self;
67
68
        #[inline]
69
        fn as_display(&'a self) -> Self::Target {
70
            Placeholder
71
        }
72
    }
73
74
    impl Display for Placeholder {
75
        fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
76
            unreachable!()
77
        }
78
    }
79
80
    impl Sealed for Placeholder {}
81
}