Skip to content

Commit 4ba1626

Browse files
committed
Implement Clone for Error.
serde_json::Error doesn't implement Clone, so wrapped it in an Arc.
1 parent 5ceb1b3 commit 4ba1626

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/errors.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::error::Error as StdError;
22
use std::fmt;
33
use std::result;
4+
use std::sync::Arc;
45

56
/// A crate private constructor for `Error`.
67
pub(crate) fn new_error(kind: ErrorKind) -> Error {
@@ -11,7 +12,7 @@ pub(crate) fn new_error(kind: ErrorKind) -> Error {
1112
pub type Result<T> = result::Result<T, Error>;
1213

1314
/// An error that can occur when encoding/decoding JWTs
14-
#[derive(Debug, Eq, PartialEq)]
15+
#[derive(Clone, Debug, Eq, PartialEq)]
1516
pub struct Error(Box<ErrorKind>);
1617

1718
impl Error {
@@ -32,7 +33,7 @@ impl Error {
3233
/// attribute makes sure clients don't count on exhaustive matching.
3334
/// (Otherwise, adding a new variant could break existing code.)
3435
#[non_exhaustive]
35-
#[derive(Debug)]
36+
#[derive(Clone, Debug)]
3637
pub enum ErrorKind {
3738
/// When a token doesn't have a valid JWT shape
3839
InvalidToken,
@@ -70,7 +71,7 @@ pub enum ErrorKind {
7071
/// An error happened when decoding some base64 text
7172
Base64(base64::DecodeError),
7273
/// An error happened while serializing/deserializing JSON
73-
Json(serde_json::Error),
74+
Json(Arc<serde_json::Error>),
7475
/// Some of the text was invalid UTF-8
7576
Utf8(::std::string::FromUtf8Error),
7677
/// Something unspecified went wrong with crypto
@@ -144,7 +145,7 @@ impl From<base64::DecodeError> for Error {
144145

145146
impl From<serde_json::Error> for Error {
146147
fn from(err: serde_json::Error) -> Error {
147-
new_error(ErrorKind::Json(err))
148+
new_error(ErrorKind::Json(Arc::new(err)))
148149
}
149150
}
150151

0 commit comments

Comments
 (0)