Skip to content

Commit

Permalink
Merge pull request #120 from ngrok/josh/common-error-pointers
Browse files Browse the repository at this point in the history
ngrok: add Error impls for common pointer types
  • Loading branch information
jrobsonchase authored Oct 27, 2023
2 parents 2a1b01e + 0fc9116 commit 40a99c4
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions ngrok/src/internals/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{
},
str::FromStr,
string::FromUtf8Error,
sync::Arc,
};

use muxado::typed::StreamType;
Expand Down Expand Up @@ -54,6 +55,42 @@ pub trait Error: error::Error {
}
}

impl<E> Error for Box<E>
where
E: Error,
{
fn error_code(&self) -> Option<&str> {
<E as Error>::error_code(self)
}
fn msg(&self) -> String {
<E as Error>::msg(self)
}
}

impl<E> Error for Arc<E>
where
E: Error,
{
fn error_code(&self) -> Option<&str> {
<E as Error>::error_code(self)
}
fn msg(&self) -> String {
<E as Error>::msg(self)
}
}

impl<'a, E> Error for &'a E
where
E: Error,
{
fn error_code(&self) -> Option<&str> {
<E as Error>::error_code(self)
}
fn msg(&self) -> String {
<E as Error>::msg(self)
}
}

#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct ErrResp {
pub msg: String,
Expand Down

0 comments on commit 40a99c4

Please sign in to comment.