1use std::error::Error as StdError;
2use std::fmt;
3
4use onc_rpc_client::RpcError;
5
6#[derive(Debug)]
10#[non_exhaustive]
11pub enum PortmapError {
12 Rpc(RpcError),
14 ProgramUnavailable,
16 InvalidPortValue(u32),
18}
19
20impl fmt::Display for PortmapError {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 match self {
23 Self::Rpc(e) => e.fmt(f),
24 Self::ProgramUnavailable => write!(f, "Program unavailable"),
25 Self::InvalidPortValue(value) => write!(f, "Invalid port value: {value}"),
26 }
27 }
28}
29
30impl StdError for PortmapError {
31 fn source(&self) -> Option<&(dyn StdError + 'static)> {
32 match self {
33 Self::Rpc(e) => Some(e),
34 Self::ProgramUnavailable | Self::InvalidPortValue(_) => None,
35 }
36 }
37}
38
39impl From<RpcError> for PortmapError {
40 fn from(e: RpcError) -> Self {
41 Self::Rpc(e)
42 }
43}
44
45impl PortmapError {
46 #[must_use]
49 pub const fn is_connection_reusable(&self) -> bool {
50 match self {
51 Self::Rpc(e) => e.is_connection_reusable(),
52 Self::ProgramUnavailable | Self::InvalidPortValue(_) => true,
53 }
54 }
55}