From c33d0b8481e1d9aa9770d7035123dc576cf4cf95 Mon Sep 17 00:00:00 2001 From: Glenn Griffin Date: Fri, 30 Aug 2019 11:37:33 -0700 Subject: [PATCH] Make RequestError Sync This requires enforcing that errors returned from TokenStorage implementations are Send, which the ones in this crate are, but is a breaking change because any external implementations may be returning errors that are !Sync currently. The motivation for this change is that Box is not as fully supported within the rust stdlib as Box. In particular there exists these two From impls: impl<'a, E: Error + 'a> From for Box impl<'a, E: Error + Send + Sync + 'a> From for Box but no corresponding impl for impl<'a, E: Error + Send + 'a> From for Box This may just be an oversight in the rust stdlib that could be fixed, but in practice it means that dealing with 'Error + Send' types is not the most ergonomic because the '?' operator can't be used to convert from a Box to a Box. Since the current implementations (not counting any external ones that may exist) implement Sync this seems like a good tradeoff to make it a little easier to use in an ergonomic way. --- src/storage.rs | 2 +- src/types.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/storage.rs b/src/storage.rs index 8c63949..f0828ab 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -20,7 +20,7 @@ use itertools::Itertools; /// For completeness, the underlying, sorted scopes are provided as well. They might be /// useful for presentation to the user. pub trait TokenStorage { - type Error: 'static + Error + Send; + type Error: 'static + Error + Send + Sync; /// If `token` is None, it is invalid or revoked and should be removed from storage. /// Otherwise, it should be saved. diff --git a/src/types.rs b/src/types.rs index 72229b7..f44dc47 100644 --- a/src/types.rs +++ b/src/types.rs @@ -71,7 +71,7 @@ pub enum RequestError { /// An error occurred while refreshing tokens. Refresh(RefreshResult), /// Error in token cache layer - Cache(Box), + Cache(Box), } impl From for RequestError {